开发者

Windows service always writes to custom log and application log

开发者 https://www.devze.com 2023-01-13 12:01 出处:网络
I am using a custom EventLog for my Windows service.The service creates the event source after installtion.I don\'t have any problems.

I am using a custom EventLog for my Windows service. The service creates the event source after installtion. I don't have any problems.

However, I have setup my service so that I can run it from the IDE using the following mechanism:

static void Main(string[] args)
{
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledException);

    string firstArgument = string.Empty;

    if (args.Length > 0)
        firstArgument = args[0].ToUpperInvariant();

    if (string.Compare(firstArgument, "-CONSOLE", true) == 0)
    {
        ne开发者_开发技巧w SchedulerService().RunConsole(args);
    }
    else
    {
        ServiceBase[] services = new ServiceBase[] { new SchedulerService() };
        ServiceBase.Run(services);
    }
}

When writing to the event log, it seems to write my custom event log AND the application log. How can I prevent this from occurring?

Below is the code I am using to write to the event log: (The EventLog app setting is the same for the source and name)

using (System.Diagnostics.EventLog eventLog = 
   new EventLog(
      System.Configuration.ConfigurationManager.AppSettings["EventLog"], ".", 
      System.Configuration.ConfigurationManager.AppSettings["EventLog"]))
{
    eventLog.WriteEntry(msg, entryType);
}


It seems that a reboot of my machine has fixed this problem. I am not sure why yet, but I am going to assume the Event Viewer mechanism got in to some kind of weird state.

0

精彩评论

暂无评论...
验证码 换一张
取 消