Difference between revisions of "CSharp - Logging"

From PeformIQ Upgrade
Jump to navigation Jump to search
(Created page with "=Notes= * <pre> using System; using System.Diagnostics; using System.Threading; class MySample{ public static void Main(){ // Create the source, if it does n...")
 
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Notes=
=Notes=


*  
* http://stackoverflow.com/questions/5057567/how-to-do-logging-in-c


<pre>
<pre>
Line 36: Line 36:
}
}
</pre>
</pre>
=log4net=
* http://logging.apache.org/log4net/
=MSDN Examples=
* http://msdn.microsoft.com/en-us/library/ms171471(v=vs.100).aspx
* http://support.microsoft.com/kb/307024
=Others=
* http://www.bondigeek.com/blog/2011/09/08/a-simple-c-thread-safe-logging-class/
* http://www.ricesharp.com/?tag=/Logger


[[Category:Logging]]
[[Category:Logging]]
[[Category:CSharp]]
[[Category:CSharp]]
[[Category:Dot.NET]]

Latest revision as of 08:25, 26 November 2012

Notes

using System;
using System.Diagnostics;
using System.Threading;

class MySample{

    public static void Main(){

        // Create the source, if it does not already exist.
        if(!EventLog.SourceExists("MySource"))
        {
             //An event log source should not be created and immediately used.
             //There is a latency time to enable the source, it should be created
             //prior to executing the application that uses the source.
             //Execute this sample a second time to use the new source.
            EventLog.CreateEventSource("MySource", "MyNewLog");
            Console.WriteLine("CreatedEventSource");
            Console.WriteLine("Exiting, execute the application a second time to use the source.");
            // The source is created.  Exit the application to allow it to be registered.
            return;
        }

        // Create an EventLog instance and assign its source.
        EventLog myLog = new EventLog();
        myLog.Source = "MySource";

        // Write an informational entry to the event log.    
        myLog.WriteEntry("Writing to event log.");

    }
}

log4net

MSDN Examples

Others