While logging is not rocket science, I don't want to learn it again on the next project, so I am saving it here. ( I am using Log4Net, but I am sure Enterprise Library or others will work similarly. )
// Configure log4net using the .config file in GLOBAL.ASAX
[assembly: XmlConfigurator(Watch = true)]
protected void Application_BeginRequest(object sender, EventArgs e)
{
XmlConfigurator.Configure();
}
In the Web.config
<log4net debug="true">
<!-- Define some output appenders -->
<appender name="trace" type="log4net.Appender.TraceAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n"/>
</layout>
</appender>
<appender name="console" type="log4net.Appender.ConsoleAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n"/>
</layout>
</appender>
<appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net">
<param name="File" value="hib_log.txt"/>
<param name="AppendToFile" value="true"/>
<param name="maximumFileSize" value="500KB"/>
<param name="RollingStyle" value="Size"/>
<param name="DatePattern" value="yyyy.MM.dd"/>
<param name="StaticLogFileName" value="true"/>
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default priority -->
<root>
<priority value="DEBUG"/>
<appender-ref ref="rollingFile"/>
</root>
<logger name="NHibernate">
<level value="WARN"/>
</logger>
<logger name="NHibernate.SQL">
<level value="DEBUG"/>
</logger>
</log4net>
No comments:
Post a Comment