Log4Net configuring log level
How do I make Log4net only log Info level logs? Is that even possible? Can you only set a threshold?
This is what I have, and it logs Info and above as I would expect. Is there anything i can do to make it only log info?
<logger name="BrokerCollection.Model.XmlDocumentCreationTask">
<appender-ref ref="SubmissionAppender"/>
<level value="Info" />
</logger>
Solution 1:
Within the definition of the appender, I believe you can do something like this:
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="INFO"/>
<param name="LevelMax" value="INFO"/>
</filter>
...
</appender>
Solution 2:
Use threshold
.
For example:
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<threshold value="WARN"/>
<param name="File" value="File.log" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Size" />
<param name="MaxSizeRollBackups" value="10" />
<param name="MaximumFileSize" value="1024KB" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Server startup] " />
<param name="Footer" value="[Server shutdown] " />
<param name="ConversionPattern" value="%d %m%n" />
</layout>
</appender>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
<threshold value="ERROR"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread]- %message%newline" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<threshold value="INFO"/>
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%d [%thread] %m%n" />
</layout>
</appender>
In this example all INFO and above are sent to Console, all WARN are sent to file and ERRORs are sent to the Event-Log.