I have a script that has multiple threads running in parallel. These threads write to a Log4Net RollingFileAppender file. Reading this log is a quite confusing since all the thread logs are mixed up. Im wondering what is a good way to write these logs, and what is the best way to read these files so reading the debugging information of a particular thread becomes easier.
Update your config file to include the thread name in the log output. If you set the Threads name in code, that same name will be logged to your file. This is a simple example of including the thread name via the log4net config file <conversionPattern> tag:
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="service.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="2MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
**<conversionPattern value="%-5level : [%t] - %message%newline" />**
</layout>
</appender>
UPDATE I wrote a simple POC app to demonstrate this. http://codereport.net/logging-the-thread-name-with-log4net/
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