Skip to content

Instantly share code, notes, and snippets.

@KyleGobel
Created June 9, 2014 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KyleGobel/78fdc6e09d7108452d2d to your computer and use it in GitHub Desktop.
Save KyleGobel/78fdc6e09d7108452d2d to your computer and use it in GitHub Desktop.
Shows how to create a Log4NetLogger using the ServiceStack logging interfaces
public class ExampleController
{
public ILog Logger {get; set;}
public void AnyMethod(int param1, int param2)
{
Logger.DebugFormat("Parameters are {0}, and {1}", param1, param2);
}
}
public override void Configure(Container container)
{
container.Register(x => new Log4NetFactory(true));
LogManager.LogFactory = container.Resolve<Log4NetFactory>();
container.Register<ILog>(x => LogManager.GetLogger(GetType()));
}
log4net.config.XmlConfigurator.Configure();
//if not using servicestack, comment out this line
(new AppHost()).Init();
//if no apphost uncomment these
//LogManager.LogFactory = new Log4NetFactory(true);
//LogManager.GetLogger("").Info("Logging enabled");
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="debugLog.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100KB" />
<staticLogFileName value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date (GMT%date{%z}) [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment