开发者

How do you add a StackTrace to every log call in log4net?

I'm using Log4Net to log a multilayer-ed Enterprise Application.

I know that when I log an exception with Log4Net, it automati开发者_运维知识库cally exposes the exception StackTrace, but I want to log the StackTrace for every log call, even if those are not exception throws.

Why do I need that?... I want to know the call origin of the log (drilldown the layers...)

Thank all...

Tiago Dias


I came to a solution to my problem. I've wrap around the log4net in my own methods and i've created LoggingEvent intances. In each instance i've used a property with Environment.StackTrace.

This way i have StackTrace foreach log event in my application, even without exceptions being throwned.

Thank U all..


You can get the caller method name and line number using %location, but not the entire stack trace without extending log4net. Check responses to this question:

Does log4net support including the call stack in a log message

Also check the PatternLayout documentation page on apache.org for other location details you can output:

http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html

Not sure if this still applies on modern computers, but the log4net documentation warns that generating caller information is costly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜