<?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>Debug Archives - Blog IT</title>
	<atom:link href="https://blogit.create.pt/category/development/debug/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/category/development/debug/</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>Log4net Initialization/Configuration alternatives</title>
		<link>https://blogit.create.pt/marcosilva/2008/02/24/log4net-initializationconfiguration-alternatives/</link>
					<comments>https://blogit.create.pt/marcosilva/2008/02/24/log4net-initializationconfiguration-alternatives/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Sun, 24 Feb 2008 11:24:06 +0000</pubDate>
				<category><![CDATA[Debug]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[Framework]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=171</guid>

					<description><![CDATA[<p>In a previous post where I talked about using log4net I used one of the alternative ways to initialize and configure the logging services. This post will summarize these alternatives. &#160; 1. Programmatic initialization The programmatic initialization should be done somewhere in your code. This was the type of initialization used on the first post [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/02/24/log4net-initializationconfiguration-alternatives/">Log4net Initialization/Configuration alternatives</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In a previous <a href="http://blogit.create.pt/blogs/marcosilva/archive/2007/07/29/Using-log4net-logging-services.aspx">post</a> where I talked about using log4net I used one of the alternative ways to initialize and configure the logging services.</p>
<p>This post will summarize these alternatives.</p>
<p>&#160;</p>
<h2>1. Programmatic initialization</h2>
<p><font size="1"><span style="font-family: courier new,courier"></span></font></p>
<p>The programmatic initialization should be done somewhere in your code.</p>
<p>This was the type of initialization used on the first post and its code is something like this.</p>
<p><font size="1"><span style="font-family: courier new,courier">using log4net;</span></font></p>
<p><font size="1"><span style="font-family: courier new,courier">using log4net.Config;</span></font></p>
<p><font size="1"><span style="font-family: courier new,courier"></span></font></p>
<p><font size="1"><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">&#160;&#160;&#160; 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">&#160;&#160;&#160; static void Main(string[] args) </span>      <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160; {</span>       <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160;&#160;&#160;&#160;&#160; // BasicConfigurator replaced with XmlConfigurator.</span>       <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160;&#160;&#160;&#160;&#160; XmlConfigurator.Configure(new System.IO.FileInfo(args[0]));</span></font></p>
<p><font size="1"><span style="font-family: courier new,courier"></span></font><font size="1"></font></p>
<p><font size="1"></font></p>
<p><font size="1"><font size="1">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font face="Courier New">&#160; log.Info(&quot;Entering application.&quot;);</font></font></font></p>
<p><font size="1"><span style="font-family: courier new,courier">&#160;&#160;&#160; }</span></font></p>
<p><font size="1"><span style="font-family: courier new,courier"></span></font><font size="1"><span style="font-family: courier new,courier">} </span></font></p>
<p><font size="1"><span style="font-family: courier new,courier"></span></font></p>
<h2>2. Assembly attribute initialization</h2>
<p>The assembly attribute initialization does not imply the inclusion of any code in your application. Instead, you just have to place an assembly level attribute in some file of your assembly. This way your code could be:</p>
<p><font size="1"><span style="font-family: courier new,courier">using log4net;</span></font></p>
<p><font face="Courier New" size="1">[assembly: log4net.Config.XmlConfigurator()]</font></p>
<p><font size="1"><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">&#160;&#160;&#160; 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">&#160;&#160;&#160; static void Main(string[] args) </span>      <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160; {</span>       <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><font face="Courier New">log.Info(&quot;Entering application.&quot;);<span style="font-family: courier new,courier"></span></font>       <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">&#160;&#160;&#160; }</span>       <br style="font-family: courier new,courier"><span style="font-family: courier new,courier">} </span></font></p>
<p>&#160;</p>
<p>The assembly level attribute by itself does not mean a instruction to initialize the logging framework. Instead, the logging framework is initialized by the first call that is made to log4net (in the example the <font face="Courier New" size="1">log.Info<font face="Verdana" size="2">) initialized. This means that when using assembly attributes you should make a logging call as soon as possible and before calling any other external assembly.</font></font></p>
<p>&#160;</p>
<p>Finally, if you are using logger objects defined per-class, a simple way to define a logger object that enables it to be copy-pasted in a very simple way is to do:</p>
<p><font face="Courier New" size="1">private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);</font></p>
<p><p>&#160;</p>
<p>This instruction uses reflection for determining the class type name that will be used in the logging messages.</p>
<p>For more information please refer to the log4net <a href="http://logging.apache.org/log4net" target="_blank">homepage</a>.</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2008/02/24/log4net-initializationconfiguration-alternatives/">Log4net Initialization/Configuration alternatives</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/marcosilva/2008/02/24/log4net-initializationconfiguration-alternatives/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Debugging Windows Services</title>
		<link>https://blogit.create.pt/marcosilva/2007/08/26/debugging-windows-services/</link>
					<comments>https://blogit.create.pt/marcosilva/2007/08/26/debugging-windows-services/#respond</comments>
		
		<dc:creator><![CDATA[Marco Silva]]></dc:creator>
		<pubDate>Sun, 26 Aug 2007 12:36:00 +0000</pubDate>
				<category><![CDATA[Debug]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Integration]]></category>
		<category><![CDATA[Windows Service]]></category>
		<category><![CDATA[Service]]></category>
		<guid isPermaLink="false">http://blogcreate.azurewebsites.net/marcosilva/?p=271</guid>

					<description><![CDATA[<p>Recently I had to develop my first Windows Service in C#. I had already done Services in C++, and I was used to launch and debug the Services thru Visual Studio (just by normally hitting F5).&#160; I was surprised to see that the normal C# Windows Service code base does not allow this to be [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/08/26/debugging-windows-services/">Debugging Windows Services</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><font size="2">Recently I had to develop my first Windows<br />
Service in C#. I had already done Services in C++, and I was used to launch and<br />
debug the Services thru Visual Studio (just by normally hitting F5).&nbsp;</font></p>
<p><font size="2">I was surprised to see that the normal C# Windows<br />
Service code base does not allow this to be possible in a &quot;out-of-the-box&quot;<br />
experience, and one had to do things like &quot;Attach to Process&quot;, and/or put in<br />
the source code &quot;System.Diagnostics.Debugger.Launch();&quot;.</font></p>
<p><font size="2">Not satisfied with these solutions, I searched<br />
the web and I found this page that as a &quot;perfect solution&quot;.</font></p>
<p><font size="2"><a href="http://theimes.com/archive/2006/12/28/Debugging-Windows-Services-is-a-Pain.aspx">http://theimes.com/archive/2006/12/28/Debugging-Windows-Services-is-a-Pain.aspx</a></font> </p>
<p><font size="2">The author developed a Service Debugger Helper<br />
class, that incorporates a GUI for allowing all the expected Start, Stop, etc,<br />
interaction with the service. It is also possible to automatically start a<br />
service by default, thus allowing the normal F5 experience.</font></p>
<p><font size="2">Check out the author article and his source<br />
code if you are interested in knowing how he made this. Also this other link<br />
could be of interest to someone.</font></p>
<p><font size="2">Run a Service without a debugger attached (.NET<br />
Windows Service Runner)</font></p>
<p><font size="2"><a href="http://theimes.com/archive/2007/08/22/net-windows-service-runner.aspx">http://theimes.com/archive/2007/08/22/net-windows-service-runner.aspx</a></font></p>
<p><font size="2">PS: Regarding the usage of Timers in Windows<br />
Services, be careful to use the ones in System.Timers.Timer, or else the timer may never (or<br />
stop) be (being) fired.</font></p>
<p>The post <a href="https://blogit.create.pt/marcosilva/2007/08/26/debugging-windows-services/">Debugging Windows 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/08/26/debugging-windows-services/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<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>
