Skip to content

Instantly share code, notes, and snippets.

@MoaidHathot
Created December 25, 2016 22:58
Show Gist options
  • Save MoaidHathot/9e90903afdcf63037aa9feb93b795a11 to your computer and use it in GitHub Desktop.
Save MoaidHathot/9e90903afdcf63037aa9feb93b795a11 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
<log4net>
<!--This custom appender handles failovers. If the first appender fails, it'll delegate the message to the back appender-->
<appender name="FailoverAppender" type="MoreAppenders.FailoverAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline"/>
</layout>
<!--This is a custom test appender that will always throw an exception -->
<!--The first and the default appender that will be used.-->
<PrimaryAppender type="MoreAppenders.ExceptionThrowerAppender" >
<ThrowExceptionForCount value="1" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline"/>
</layout>
</PrimaryAppender>
<!--This appender will be used only if the PrimaryAppender has failed-->
<FailOverAppender type="log4net.Appender.RollingFileAppender">
<file value="log.txt"/>
<rollingStyle value="Size"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="100mb"/>
<appendToFile value="true"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger - %message%newline"/>
</layout>
</FailOverAppender>
</appender>
<root>
<level value="ALL"/>
</root>
<!--This can be either a full qualified type name or a random string that you selected as a name-->
<logger name="MoreAppenders.Program">
<level value="ALL"/>
<!--configures the FailOverAppender-->
<appender-ref ref="FailoverAppender"/>
</logger>
</log4net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment