I have wrapped Log4net in a static wrapper and want to log
loggingEvent.LocationInformation.MethodName loggingEvent.LocationInformation.ClassName
However all I get is the name of my wrapper.
How can I log that info using a forwardingappender and a static wrapper class like
Logger.Debug("Logging to Debug"); Logger.Info("Logging to Info"); Logger.Warn("Logging to Warn"); Logger.Error(ex); Logger.Fatal(ex);
You can't log to separate appenders - you need to configure different loggers, and attach the appropriate appender to each one. Then log different messages to the different loggers.
log4net doesn't support the concept of structured logging. Like shown in the conversionPattern element in the XML configuration, you have some variables to play with when writing to the storage. But including properties like FirstName in the Serilog example isn't available.
"When set to Once the log file will be rolled when the appender is configured. This effectively means that the log file can be rolled once per program execution. So, when you set your RollingFileAppender to "once", then every time you execute your program, a new log file will be created.
What about the %M
and %C
variables? http://logging.apache.org/log4net/log4net-1.2.11/release/sdk/log4net.Layout.PatternLayout.html
Usage, something like:
<layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger [%M %C] - %message%newline" /> </layout>
Doesn't that do what you are after?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With