Fluent Ribbon Control Suite is a free ribbon control for your WPF applications. You can find more information about this great control on codeplex.
Roman's blog
Human knowledge belongs to the world.
March 13, 2010
February 5, 2010
Simple guide for log4net
log4net is a tool that can help you log almost anything from your .NET applications to various places like text files, console, event log or you can even log through the network. The power of this solution is not only where you can log but it is the way you set up that logging. This text is intended as a brief and short information on how to set up and use log4net. So let's go.
Usually you set up log4net using the app.config (or web.config) or any other configuration file you use. The first thing you need to do is to add a section to your configuration, something like this:
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
Then add the section for log4net:
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="BigXmlReader.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="OutputDebugStringAppender" type="log4net.Appender.OutputDebugStringAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="OutputDebugStringAppender" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>Now you are ready to use log4net in your application. In order to do it, you need to add a reference to log4net.dll and start the log4net. You can do it by calling this
log4net.Config.XmlConfigurator.Configure();
anywhere at the start of your application so that it is possible to use log4net anywhere in your code. The last thing you need to do is to declare a logger in your class:
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
and then use it anywhere you need to log some event. There are several priorities which you can log with. There are debug, info, warn, error and fatal levels. Use appropriate methods on the log instance. For instance:
log.DebugFormat("Logging {0}", "something");For detailed information about log4net visit its website.
Subscribe to:
Posts (Atom)