cjbhaines / Log4Net.Async

Asynchronous Log4Net appenders and forwarder
http://www.nuget.org/packages/Log4Net.Async/
MIT License
121 stars 37 forks source link

The foreground thread did not exit properly #18

Closed duongphuhiep closed 8 years ago

duongphuhiep commented 8 years ago

I use the Log4Net.Async in a WinForm application.

When I closed the Main application form to exit the program, the application process was still running.

My app did not terminated properly because there are still Foreground thread running. I think that the foreground thread was created by Log4Net.Async, and it did not stop properly after disposing the appender..

Here is my actual configuration log4net

<log4net>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
        <file value=".\Logs\ReconciliationHelper.log" />
        <appendToFile value="true" />
        <rollingStyle value="Date" />
        <datePattern value="'.'yyyy-MM-dd" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%d %-5level - %message  [%logger{1}:%L]%newline" />
            <conversionPattern value="%d %-5level - %message  [%logger{1}]%newline" />
        </layout>
    </appender>
    <appender name="AsyncRollingFileAppender" type="Log4Net.Async.AsyncForwardingAppender,Log4Net.Async">
        <appender-ref ref="RollingFileAppender" />
    </appender>
    <root>
        <level value="DEBUG" />
        <appender-ref ref="AsyncRollingFileAppender" />
    </root>
</log4net>

if I didn't use the AsyncRollingFileAppender, the application process will gracefully stop

cjbhaines commented 8 years ago

Make sure you call LogManager.Shutdown() in your exiting code.