Created
June 9, 2014 21:27
-
-
Save KyleGobel/78fdc6e09d7108452d2d to your computer and use it in GitHub Desktop.
Shows how to create a Log4NetLogger using the ServiceStack logging interfaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExampleController | |
{ | |
public ILog Logger {get; set;} | |
public void AnyMethod(int param1, int param2) | |
{ | |
Logger.DebugFormat("Parameters are {0}, and {1}", param1, param2); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override void Configure(Container container) | |
{ | |
container.Register(x => new Log4NetFactory(true)); | |
LogManager.LogFactory = container.Resolve<Log4NetFactory>(); | |
container.Register<ILog>(x => LogManager.GetLogger(GetType())); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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