<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>.Net Dev</title><link>http://insario.com/blog/jfk/category/12.aspx</link><description>General posts about developing in .Net</description><managingEditor>Josh Kewley</managingEditor><dc:language>en-US</dc:language><generator>.Text Version 0.95.2004.102</generator><item><dc:creator>Josh Kewley</dc:creator><title>Setting the log file location at runtime with a DOM configured log4net</title><link>http://insario.com/blog/jfk/archive/2004/11/30/164.aspx</link><pubDate>Tue, 30 Nov 2004 09:49:00 GMT</pubDate><guid>http://insario.com/blog/jfk/archive/2004/11/30/164.aspx</guid><wfw:comment>http://insario.com/blog/jfk/comments/164.aspx</wfw:comment><comments>http://insario.com/blog/jfk/archive/2004/11/30/164.aspx#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://insario.com/blog/jfk/comments/commentRss/164.aspx</wfw:commentRss><trackback:ping>http://insario.com/blog/jfk/services/trackbacks/164.aspx</trackback:ping><description>&lt;P&gt;&lt;FONT face=Arial size=2&gt;We use log4net 1.2 beta 8 in our web applications for tracing and debugging purposes. Log4Net is great, but as with any community project, you always wish it had built in functionality to do a few extra things. In our case, I wanted to be able to log all statements to a file in a folder that exists off the web root. By default, log4net will log to a file relative to the virtual directory where the application that is logging is defined. For example, the following log4net configuration will log to a file named TmsLog.txt in the same folder as the web.config that this entry exists in:&lt;/FONT&gt;&lt;/P&gt;
&lt;DIV class=cf&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;156&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class=cb1&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;log4net&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;157&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;appender&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;name&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="TMSAppender"&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;type&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="log4net.Appender.FileAppender,log4net"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;158&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;param&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;name&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="File"&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;value&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="TmsLog.txt"&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb1&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;159&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;param&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;name&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="AppendToFile"&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;value&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="true"&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb1&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;160&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;layout&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;type&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="log4net.Layout.PatternLayout,log4net"&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;161&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;param&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;name&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="ConversionPattern"&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;value&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="%d %-5p - %m%n"&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb1&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;162&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;layout&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;163&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;appender&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;164&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;root&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;165&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;priority&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;value&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="DEBUG"&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb1&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;166&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;appender-ref&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;ref&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="TMSAppender"&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb1&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;167&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;root&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;168&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class=cb1&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;log4net&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;STYLE type=text/css&gt;
.cf { font-family: Courier New; font-size: 10pt; color: #000000; background: #ffffff; border-top: windowtext 1pt solid; padding-top: 0pt; border-left: windowtext 1pt solid; padding-left: 0pt; border-right: windowtext 1pt solid; padding-right: 0pt; border-bottom: windowtext 1pt solid; padding-bottom: 0pt; }
.cl { margin: 0px; }
.cln { color: #008080; background: #ffffff; }
.cb1 { color: #0000ff; }
.cb2 { color: #800000; }
.cb3 { color: #ff00ff; }
.cb4 { color: #ff0000; }
&lt;/STYLE&gt;

&lt;P&gt;&lt;FONT face=Arial size=2&gt;I wanted to be able to specify the file location at run time, which lead me into a few traps.&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face=Arial size=2&gt;A coworker pointed out that I could simply use relative paths in the configuration file:&lt;/FONT&gt; 
&lt;DIV class=cf&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;158&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=cb2&gt;param&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;name&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="File"&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb4&gt;value&lt;/SPAN&gt;&lt;SPAN class=cb1&gt;="..\\LogLocation\\TmsLog.txt"&lt;/SPAN&gt;&lt;SPAN class=cb3&gt; &lt;/SPAN&gt;&lt;SPAN class=cb1&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;This is ok, but our Dev, QA, and Production environments are all a little different. We'd written a utility object that uses some logic to determine the current execution environment and return the correct folder to use for logging purposes. What I really wanted was to be able to use the information provided by this library to change the logging folder at runtime. One option was to create the configuration programmatically, but I wanted to stay with the basic DomConfigurator.Configure() solution.&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face=Arial size=2&gt;The first programmatic solution that I tried was to change the file path at runtime. The following code does allow me to change the path of the configured path, but for some reason it didn't 'stick', and the path used in the configuration file was used instead: &lt;/FONT&gt;&lt;/P&gt;&lt;FONT face=Arial size=2&gt;
&lt;DIV class=cf&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;22&lt;/SPAN&gt;&amp;nbsp;ILog myLog=LogManager.GetLogger(&lt;SPAN class=cb1&gt;typeof&lt;/SPAN&gt;(Logger));&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;23&lt;/SPAN&gt;&amp;nbsp;ILoggerRepository aRepos = myLog.Logger.Repository;&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;24&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class=cb1&gt;foreach&lt;/SPAN&gt;(IAppender anAppender &lt;SPAN class=cb1&gt;in&lt;/SPAN&gt; ((log4net.Repository.Hierarchy.Hierarchy)aRepos).Root.Appenders)&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;25&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;if&lt;/SPAN&gt; (anAppender &lt;SPAN class=cb1&gt;is&lt;/SPAN&gt; FileAppender)&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;26&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ((FileAppender)anAppender).File = @"c:\temp\test.txt";&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;27&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class=cb1&gt;return&lt;/SPAN&gt; myLog;&lt;/PRE&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;My&amp;nbsp;shorthand approach to this was the following:&lt;/FONT&gt;&lt;FONT face=Arial size=2&gt; 
&lt;DIV class=cf&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;28&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class=cb1&gt;public&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;static&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;string&lt;/SPAN&gt; LogFile&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;29&lt;/SPAN&gt;&amp;nbsp;{&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;30&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;get&lt;/SPAN&gt;{ &lt;SPAN class=cb1&gt;return&lt;/SPAN&gt; ((FileAppender)((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetLoggerRepository()).Root.Appenders[0]).File;}&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;31&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;set&lt;/SPAN&gt;{ ((FileAppender)((log4net.Repository.Hierarchy.Hierarchy)LogManager.GetLoggerRepository()).Root.Appenders[0]).File = &lt;SPAN class=cb1&gt;value&lt;/SPAN&gt;;}&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;32&lt;/SPAN&gt;&amp;nbsp;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;Again, no dice. Finally, after a little digging, I came across an email on the log4Net discussion list that pointed me in the right direction. I created my own FileAppender class that derived from the log4net FileAppender, and overwrote the File property:&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face=Arial size=2&gt;
&lt;DIV class=cf&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;76&lt;/SPAN&gt;&amp;nbsp;&lt;SPAN class=cb1&gt;public&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;class&lt;/SPAN&gt; InsarioWebLogFileAppender : log4net.Appender.FileAppender&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;77&lt;/SPAN&gt;&amp;nbsp;{&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;78&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;public&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;override&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;string&lt;/SPAN&gt; File &lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;79&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;80&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;get&lt;/SPAN&gt;{&lt;SPAN class=cb1&gt;return&lt;/SPAN&gt; &lt;SPAN class=cb1&gt;base&lt;/SPAN&gt;.File;}&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;81&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class=cb1&gt;set&lt;/SPAN&gt;{&lt;SPAN class=cb1&gt;base&lt;/SPAN&gt;.File = Web.WebEnvironment.LogDirectory + &lt;SPAN class=cb1&gt;value&lt;/SPAN&gt;;}&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;82&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;PRE class=cl&gt;&lt;SPAN class=cln&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;83&lt;/SPAN&gt;&amp;nbsp;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Arial size=2&gt;Originally I tried to store the file setting in a local variable and return it in the getter but that didn't work, probably due to caching and optimization techniques used in the internals of log4net. Instead,&amp;nbsp;I&amp;nbsp;had to set the property on the base entity, as you see above.&lt;/FONT&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;img src ="http://insario.com/blog/jfk/aggbug/164.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Josh Kewley</dc:creator><title>New article on creating a plugin for UnleashIt</title><link>http://insario.com/blog/jfk/archive/2004/11/17/160.aspx</link><pubDate>Wed, 17 Nov 2004 15:20:00 GMT</pubDate><guid>http://insario.com/blog/jfk/archive/2004/11/17/160.aspx</guid><wfw:comment>http://insario.com/blog/jfk/comments/160.aspx</wfw:comment><comments>http://insario.com/blog/jfk/archive/2004/11/17/160.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://insario.com/blog/jfk/comments/commentRss/160.aspx</wfw:commentRss><trackback:ping>http://insario.com/blog/jfk/services/trackbacks/160.aspx</trackback:ping><description>&lt;P&gt;&lt;FONT face=Arial size=2&gt;I just wrote an &lt;A href="http://insario.com/blog/jfk/articles/159.aspx"&gt;article &lt;/A&gt;that covers my experience building a plugin for &lt;A href="http://www.eworldui.net/UnleashIt/"&gt;UnleashIt &lt;/A&gt;this week. UnleashIt is a sweet utility that belongs in the toolbox of any .Net developer who is in charge of releasing updates. The new ability for the control to support plugins only adds to its value. Anyway, &lt;A href="http://insario.com/blog/jfk/articles/159.aspx"&gt;have a look at my article &lt;/A&gt;if you're interested.&lt;/FONT&gt;&lt;/P&gt;&lt;img src ="http://insario.com/blog/jfk/aggbug/160.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Josh Kewley</dc:creator><title>PatternLayout modifiers in log4net</title><link>http://insario.com/blog/jfk/archive/2004/10/26/156.aspx</link><pubDate>Tue, 26 Oct 2004 19:05:00 GMT</pubDate><guid>http://insario.com/blog/jfk/archive/2004/10/26/156.aspx</guid><wfw:comment>http://insario.com/blog/jfk/comments/156.aspx</wfw:comment><comments>http://insario.com/blog/jfk/archive/2004/10/26/156.aspx#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://insario.com/blog/jfk/comments/commentRss/156.aspx</wfw:commentRss><trackback:ping>http://insario.com/blog/jfk/services/trackbacks/156.aspx</trackback:ping><description>&lt;P&gt;&lt;FONT face=Arial size=2&gt;I was trying to implement log4net on a computer that didn't have the SDK installed recently and couldn't find information on how to format the output log on the web. This data comes from the log4net SDK - I figured I'd blog it for someone's future benefit...&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE cellSpacing=0 cellPadding=0 border=1&gt;
&lt;TBODY&gt;
&lt;TR vAlign=top&gt;
&lt;TH width="10%"&gt;&lt;FONT size=2&gt;Conversion Character&lt;/FONT&gt;&lt;/TH&gt;
&lt;TH width="90%"&gt;&lt;FONT size=2&gt;Effect&lt;/FONT&gt;&lt;/TH&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;a&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size=2&gt;Used to output the frienly name of the AppDomain where the logging event was generated.&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;c&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the logger of the logging event. The logger conversion specifier can be optionally followed by &lt;I&gt;precision specifier&lt;/I&gt;, that is a decimal constant in brackets.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;If a precision specifier is given, then only the corresponding number of right most components of the logger name will be printed. By default the logger name is printed in full.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;For example, for the logger name "a.b.c" the pattern &lt;B&gt;%c{2}&lt;/B&gt; will output "b.c".&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;C&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the fully qualified class name of the caller issuing the logging request. This conversion specifier can be optionally followed by &lt;I&gt;precision specifier&lt;/I&gt;, that is a decimal constant in brackets.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;If a precision specifier is given, then only the corresponding number of right most components of the class name will be printed. By default the class name is output in fully qualified form.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;For example, for the class name "log4net.Layout.PatternLayout", the pattern &lt;B&gt;%C{1}&lt;/B&gt; will output "PatternLayout".&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;B&gt;WARNING&lt;/B&gt; Generating the caller class information is slow. Thus, it's use should be avoided unless execution speed is not an issue.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;d&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the date of the logging event. The date conversion specifier may be followed by a &lt;I&gt;date format specifier&lt;/I&gt; enclosed between braces. For example, &lt;B&gt;%d{HH:mm:ss,fff}&lt;/B&gt; or &lt;B&gt;%d{dd MMM yyyy HH:mm:ss,fff}&lt;/B&gt;. If no date format specifier is given then ISO8601 format is assumed (ISO8601DateFormatter).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;The date format specifier admits the same syntax as the time pattern string of the ToString.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;For better results it is recommended to use the log4net date formatters. These can be specified using one of the strings "ABSOLUTE", "DATE" and "ISO8601" for specifying AbsoluteTimeDateFormatter, and respectively ISO8601DateFormatter. For example, &lt;B&gt;%d{ISO8601}&lt;/B&gt; or &lt;B&gt;%d{ABSOLUTE}&lt;/B&gt;.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;These dedicated date formatters perform significantly better than ToString.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;F&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the file name where the logging request was issued.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;B&gt;WARNING&lt;/B&gt; Generating caller location information is extremely slow. It's use should be avoided unless execution speed is not an issue.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;l&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output location information of the caller which generated the logging event.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;The location information depends on the CLI implementation but usually consists of the fully qualified name of the calling method followed by the callers source the file name and line number between parentheses.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;The location information can be very useful. However, it's generation is &lt;B&gt;extremely&lt;/B&gt; slow. It's use should be avoided unless execution speed is not an issue.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;L&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the line number from where the logging request was issued.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;B&gt;WARNING&lt;/B&gt; Generating caller location information is extremely slow. It's use should be avoided unless execution speed is not an issue.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;m&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the application supplied message associated with the logging event.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;M&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the method name where the logging request was issued.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;B&gt;WARNING&lt;/B&gt; Generating caller location information is extremely slow. It's use should be avoided unless execution speed is not an issue.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;n&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Outputs the platform dependent line separator character or characters.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;This conversion character offers practically the same performance as using non-portable line separator strings such as "\n", or "\r\n". Thus, it is the preferred way of specifying a line separator.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;p&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the level of the logging event.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;P&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the an event specific property. The key to lookup must be specified within braces and directly following the pattern specifier, e.g. &lt;CODE&gt;%X{user}&lt;/CODE&gt; would include the value from the property that is keyed by the string 'user'. Each property value that is to be included in the log must be specified separately. Properties are added to events by loggers or appenders. By default no properties are defined.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;r&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the number of milliseconds elapsed since the start of the application until the creation of the logging event.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;t&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the name of the thread that generated the logging event. Uses the thread number if no name is available.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;u&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the user name for the currently active user (Principal.Identity.Name).&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;B&gt;WARNING&lt;/B&gt; Generating caller information is extremely slow. It's use should be avoided unless execution speed is not an issue.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;W&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the WindowsIdentity for the currently active user.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;B&gt;WARNING&lt;/B&gt; Generating caller WindowsIdentity information is extremely slow. It's use should be avoided unless execution speed is not an issue.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;x&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the NDC (nested diagnostic context) associated with the thread that generated the logging event.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;X&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;Used to output the MDC (mapped diagnostic context) associated with the thread that generated the logging event. The key to lookup must be specified within braces and directly following the pattern specifier, e.g. &lt;CODE&gt;%X{user}&lt;/CODE&gt; would include the value from the MDC that is keyed by the string 'user'. Each MDC value that is to be included in the log must be specified separately.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR vAlign=top&gt;
&lt;TD align=middle&gt;&lt;FONT size=2&gt;%&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;FONT size=2&gt;The sequence %% outputs a single percent sign.&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;img src ="http://insario.com/blog/jfk/aggbug/156.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>