Logging to two different log files with log4net

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:13.333333969116211px; line-height:16.666667938232422px I am attempting to log error messages as well as debug messages to two different files. I am using two different
file appenders to do this. Here is my app.config file
<pre class="prettyprint <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="DebugFileAppender" type="log4net.Appender.FileAppender
<param name="File" value="DebugLog.log" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout
<param name="ConversionPattern" value="%date %level %logger - %message %newline" />
</layout>
<filter type="log4net.Filter.LevelMatchFilter
<levelToMatch value="DEBUG"/>
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
</appender>

<appender name="ErrorFileAppender" type="log4net.Appender.FileAppender
<param name="File" value="ErrorLog.log" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout
<param name="ConversionPattern" value="%date %level %logger %type %exception %line %location - %message %newline" />
</layout>
<filter type="log4net.Filter.LevelMatchFilter
<levelToMatch value="ERROR"/>
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
</appender>

<root>
<level value="DEBUG" />
<appender-ref ref="DebugFileAppender" />
</root>

<logger name="ErrorFileAppender" >
<level value="ERROR"/>
<appender-ref ref="ErrorFileAppender"/>
</logger>[/code]
<br/>
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:13.333333969116211px; line-height:16.666667938232422px The debug messages work fine but when i alter the program to contain an exception error, the error is not written
to the file. Here is the code i use to catch the exception
<pre class="prettyprint try
{
//some code here
}
catch(Exception e)
{
logger.Error(e);
}[/code]
<br/>
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:13.333333969116211px; line-height:16.666667938232422px <span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:13.333333969116211px; line-height:16.666667938232422px
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:13.333333969116211px; line-height:16.666667938232422px

View the full article
 
Back
Top