Friday, November 21, 2008   
  Search  
 
Register  Login  
Home  
   Error Logging in C#.Net Minimize  
Location: BlogsThe Soapbox    
Posted by: Daniel Phelps 8/25/2008 9:50 AM

So hey.

I'm working on this project where I'll have three instances of a .NET Forms application and an ASP.NET application reading from and writing to the same database.  Since there is a small amount of information in the database, there's a chance that two users will end up modifying the same piece of information.  I won't be around to watch it happen, so I need to make sure the exception's message and stack trace are written down.  I'm not so sure if this works in ASP.NET, but (according to MSDN documentation) it works in Windows Forms as long as your application is granted 'write' permission.  Also, make sure you have referenced System.dll and you are using System.Diagnostics.

Happy error logging. 

   1:          public static void LogError(Exception ex, EventLog eventLog)
   2:          {
   3:              if (!(EventLog.SourceExists("MySource")))
   4:              {
   5:                  EventLog.CreateEventSource("MySource", "MyLogName");
   6:              }
   7:              eventLog.Source = "MySource";
   8:              eventLog.WriteEntry(ex.Message + " " + ex.StackTrace, System.Diagnostics.EventLogEntryType.Error);
   9:          }
Permalink |  Trackback

Comments (1)   Add Comment
Re: Error Logging in .Net 3.5 - C#    By BrittPhelps on 5/14/2008 7:48 PM
This is my first comment!! I'm not sure what to comment on about this post though... I am confused by the title alone...


Your name:
Title:
Comment:
Add Comment   Cancel 
     
  
   All Blogs Minimize  
     
 Print   
   Archive Minimize  
     
 Print   
   Search the blog Minimize  
     
 Print