EL 中的 Logger.Write 方法是否缺少重载?其他日志框架提供这些 API 吗?
我最近开始使用 Enterprise Library 5.0 日志块并有两个观察结果。
我的日志记录格式是时间戳、严重性和消息本身。我找不到任何采用消息和严重性级别参数的 Logger.Write 方法的重载。显然,我可以使用其他重载,例如类别、eventId、优先级等。有点奇怪的是,没有像
这样的消息和严重性重载public static void Write(对象消息,TraceEventType严重性);
有人有相同的观察结果还是我遗漏了什么?
我也没有找到任何采用 Exception 对象参数的 Logger.Write 重载。这对我来说也有点令人惊讶。如果有一个采用异常对象并记录诸如堆栈跟踪、内部异常等内容的重载,那就太好了。其他人也觉得奇怪吗?
我猜测其他框架(例如 log4net、NLog)在其 API 中提供了此类接口?
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用带有 LogEntry 的 Write 重载即可。您可以创建 LogEntry 并仅设置您关心的属性。您始终可以获取 Exception 对象上的 StackTrace 并将其添加到日志条目中。
通过策略记录异常的另一个选项是 异常处理块。
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.