<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Audit Archives - Blog IT</title>
	<atom:link href="https://blogit.create.pt/category/development/audit/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/category/development/audit/</link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Thu, 10 Jan 2019 14:18:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Using log4net logging services</title>
		<link>https://blogit.create.pt/marcosilva/2007/07/29/using-log4net-logging-services/</link>
					<comments>https://blogit.create.pt/marcosilva/2007/07/29/using-log4net-logging-services/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Sun, 29 Jul 2007 11:22:00 +0000</pubDate>
				<category><![CDATA[Debug]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[Framework]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=291</guid>

					<description><![CDATA[<p>Whenever you have the need for debugging some application that by whatever reason cannot be properly debugged in Visual Studio, or even because your application requires some kind of logging/auditing functionality, instead of developing your own tool you have the option to use some existent logging frameworks. One that I have tried and enjoyed its [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/07/29/using-log4net-logging-services/">Using log4net logging services</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><font size="2">Whenever you have the need for debugging some application that by whatever reason cannot be properly debugged in Visual Studio, or even because your application requires some kind of logging/auditing functionality, instead of developing your own tool you have the option to use some existent logging frameworks.</font></p>
<p><font size="2">One that I have tried and enjoyed its features and ease of use is log4net &#8211; <a href="http://logging.apache.org/log4net/" title="http://logging.apache.org/log4net/" target="_blank">http://logging.apache.org/log4net/</a>.</font></p>
<p><font size="2">Like they say on their webpage, &quot;<span style="font-style: italic">log4net is a tool to help the programmer output log statements to a variety<br />
                    of output targets. log4net is a port of the excellent log4j framework to the<br />
                    .NET runtime</span>&quot;.  Its features are present here: <a href="http://logging.apache.org/log4net/release/features.html" title="http://logging.apache.org/log4net/release/features.html" target="_blank">http://logging.apache.org/log4net/release/features.html.</a></font></p>
<p><font size="2">One of its great features is the ability to control and configure the logging framework entirely by an XML file. This allows the building and deployment of applications that at run-time can dynamically change its logging configuration. For this you should initialize to log in the following manner (in the example the XML configuration file is received in the application arguments):<br /></font></p>
<p><font size="1"><span style="font-family: courier new,courier">// Import log4net classes.</span><br style="font-family: courier new,courier"><span style="font-family: courier new,courier">using log4net;</span><br style="font-family: courier new,courier"><span style="font-family: courier new,courier">using log4net.Config;</span><br style="font-family: courier new,courier"><br style="font-family: courier new,courier"><span style="font-family: courier new,courier">public class MyApp </span><br style="font-family: courier new,courier"><span style="font-family: courier new,courier">{</span><br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&nbsp;&nbsp;&nbsp; private static readonly ILog log = LogManager.GetLogger(typeof(MyApp));</span><br style="font-family: courier new,courier"><br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&nbsp;&nbsp;&nbsp; static void Main(string[] args) </span><br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&nbsp;&nbsp;&nbsp; {</span><br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // BasicConfigurator replaced with XmlConfigurator.</span><br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlConfigurator.Configure(new System.IO.FileInfo(args[0]));</span><span style="font-family: courier new,courier">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: courier new,courier"></span><br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,courier"><span style="font-family: courier new,courier">} </span></font></p>
<p>After this, you can check if the initialization went ok by testing the value of: <font size="1"><span style="font-family: courier new,courier">_log.Logger.Repository.Configured .</span></font></p>
<p>Now it is real easy to start logging things. You just have to do:</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <font size="1"><span style="font-family: courier new,courier">log.Info(&quot;Entering application.&quot;);</span><br style="font-family: courier new,courier"><br />
<span style="font-family: courier new,courier">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; log.Debug(&quot;Entering application.&quot;);</span></font></p>
<p>and the framework takes care of the rest, logging acording to the configuration that you provided. Note that in the above code I am already logging into two different log levels, just as an example for showing you, that while developing I can have the level configured at DEBUG, and at&nbsp;production I can reduce the level to INFO, or even NONE, if I dont want any logging at all. If a problem occurs in production, I can just as easily change the log level to DEBUG again, and without having to change anything in the application, the logs start being generated.&nbsp;</p>
<p>As a final example of the capabilities of the framework, I just want to show here a possible XML configuration file:</p>
<p style="font-family: courier new,courier"><font size="1">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;<br />&lt;log4net&gt;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;!&#8211; Rolling File Appender &#8211;&gt;<br />&nbsp;&nbsp;&nbsp; &lt;appender name=&quot;RollingFileAppender&quot; type=&quot;log4net.Appender.RollingFileAppender&quot;&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;file value=&quot;log-file.txt&quot; /&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;appendToFile value=&quot;true&quot; /&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;maximumFileSize value=&quot;1KB&quot; /&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;maxSizeRollBackups value=&quot;0&quot; /&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;staticLogFileName value=&quot;true&quot; /&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;layout type=&quot;log4net.Layout.PatternLayout&quot;&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;conversionPattern value=&quot;%date [%thread] %-5level %logger &#8211; %message%newline&quot; /&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/layout&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/appender&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;!&#8211; Console appender &#8211;&gt;<br />&nbsp;&nbsp;&nbsp; &lt;appender name=&quot;ConsoleAppender&quot; type=&quot;log4net.Appender.ConsoleAppender&quot;&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;target value=&quot;Console.Error&quot; /&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;layout type=&quot;log4net.Layout.PatternLayout&quot;&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;conversionPattern value=&quot;%message%newline&quot; /&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/layout&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/appender&gt;<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; &lt;root&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;level value=&quot;DEBUG&quot; /&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&lt;appender-ref ref=&quot;RollingFileAppender&quot; /&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&lt;appender-ref ref=&quot;ConsoleAppender&quot; /&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/root&gt;&nbsp;&nbsp;&nbsp; <br />&lt;/log4net&gt;&nbsp;</font></p>
<p>In this configuration, I define two different appenders (RollingFile and Console), each with its own configuration. At the root level, I define the logging level at DEBUG (so I want to see everything until this level), and that the logging should be done to the two defined appenders. So, when I log something with this configuration, the log is done to a file and to the application&#039;s console.</p>
<p>So, you see that it is easy to add logging capabilities to your application.&nbsp;</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/07/29/using-log4net-logging-services/">Using log4net logging services</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2007/07/29/using-log4net-logging-services/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
