Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading log from Log4Net generated by multiple threads

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.

like image 609
Benjamin Ortuzar Avatar asked Mar 02 '10 20:03

Benjamin Ortuzar


1 Answers

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/

like image 89
Athens Holloway Avatar answered Sep 29 '22 23:09

Athens Holloway