How to add stacktrace for every log call in log4net?

I am using Log4Net to register a tiered Enterprise Application.

I know that when I log an exception with Log4Net, it automatically throws a StackTrace exception, but I want to log a StackTrace for every log call, even if they are not exceptions.

Why do I need this? ... I want to know the origin of the log call (layering ...)

Thanks everyone ...

Thiago Diaz

+4
source share
2 answers

I came to a solution to my problem. I wrap log4net in my own methods, and I created LoggingEvent entries. In each instance, I used a property with Environment.StackTrace.

Thus, I have a StackTrace foreach log event in my application, even if exceptions are possible.

Thanks to everyone ..

+3
source

You can get the call method name and line number using% location, but not the whole stack trace without the log4net extension. Check the answers to this question:

Does support log4net, including call stack, in the log message

Also check the PatternLayout documentation page on apache.org for other location data that you can display:

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

+1
source

Source: https://habr.com/ru/post/1306461/


All Articles