2010-08-24 101 views
2

我为我的Windows服务使用自定义EventLog。该服务在安装后创建事件源。我没有任何问题。Windows服务始终写入自定义日志和应用程序日志

不过,我安装我的服务,这样我可以从IDE使用下面的机制运行它:

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) 
    { 
     new SchedulerService().RunConsole(args); 
    } 
    else 
    { 
     ServiceBase[] services = new ServiceBase[] { new SchedulerService() }; 
     ServiceBase.Run(services); 
    } 
} 

当写入事件日志,它似乎写我的自定义事件日志和应用程序登录。我怎样才能防止这种情况发生?

下面是我使用写入事件日志代码:(事件日志的应用程序设置为源和名称相同)

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

回答

2

看来,我的机器重新启动已经修复了这个问题。我不确定为什么,但是我将假设事件查看器机制进入某种奇怪的状态。