Saturday, April 14, 2012 5:52 PM
I have a .NET 4.0 Windows service that runs un-attended on a Win2008 R2 box. Occasionally it may experience unexpected errors that I need to handle and log so the service does not crash. Unfortunately, my error logging code that uses the .NET EventLog class blows up when I try to create the event source and my app dies. Here is the full stack trace:
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentException
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
I wrote a EventlogLogger class that wraps the .NET Eventlog class. Here is the relevant code in that clas:
public class EventlogLogger
private const string SOURCE = "Test Agent";
private const string LOG = "Application";
private bool m_initialized = false;
public void Initialize()
EventLog.CreateEventSource(SOURCE, LOG); //we die here with ArgumentNullException
m_initialized = true;
My service is running as a domain user that is a local admin on that box.
Why does EventLog.CreateEventSource fail with ArgumentNullException?
- Edited by scott_m Saturday, April 14, 2012 5:58 PM na
Saturday, April 14, 2012 9:56 PMCan you write t the file? I think the permision on the file iws incorrect. What folder is the file located? Do you have write permission?
Saturday, April 14, 2012 10:59 PMIt didn't fail with a Null exception, it failed with an ArgumentException. If you run this under the debugger you should be able to see what the Message field in the exception says.