EventLog.CreatEventSource issue
-
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:
Application: MyServiceApp.impl.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.ArgumentException
Stack:
at System.Diagnostics.EventLog.CreateEventSource(System.Diagnostics.EventSourceCreationData)
at TestUtil.Impl.EventlogLogger.Initialize()
at TestAgent.Impl.TestRunnerManager.LogError(System.Exception)
at TestAgent.Impl.TestRunner.DoTest()
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)
at System.Threading.ThreadHelper.ThreadStart()
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()
{
if (!EventLog.SourceExists(SOURCE))
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
All Replies
-
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?
jdweng
-
Saturday, April 14, 2012 10:59 PM
It 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.- Proposed As Answer by Mike FengMicrosoft Contingent Staff, Moderator Tuesday, April 17, 2012 8:05 AM
- Marked As Answer by scott_m Tuesday, April 17, 2012 9:27 PM

