I have recently start using Enterprise library 5.0 logging block and have two observations.
My format for logging is timestamp, severity and the message itself. I could not find any overload of Logger.Write method that takes message and severity level parameters. Obviously I can use other overloads that take things like category, eventId, priority etc. It’s a bit strange that there is no overload just for message and severity like
public static void Write(object message, TraceEventType severity);
Does anyone 开发者_Go百科has same observation or am I missing anything?
I also did not find any overload for Logger.Write that takes Exception object parameter. That’s kind of surprising for me also. It would be nice to have an overload that take exception object and logs things like stacktrace, inner exception etc. Anyone else find it surprising too?
I am guessing that other frameworks like (log4net, NLog) have this type of interfaces available in their APIs?
Just use the Write overload that takes a LogEntry. You can create a LogEntry and set only those properties you care about. You can always get StackTrace on your Exception object and add it to your log entry.
Another option for logging exceptions through policies is the Logging handler of the Exception Handling Block.
精彩评论