开发者

Does Logger.Write method in EL has missing overloads? Other logging framework offer these APIs?

开发者 https://www.devze.com 2023-02-11 01:51 出处:网络
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 Logg

I have recently start using Enterprise library 5.0 logging block and have two observations.

  1. 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?

  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消