【问题标题】:Windows service always writes to custom log and application logWindows 服务始终写入自定义日志和应用程序日志
【发布时间】:2010-08-24 17:39:13
【问题描述】:

我正在为我的 Windows 服务使用自定义 EventLog。该服务在安装后创建事件源。我没有任何问题。

但是,我已经设置了我的服务,以便我可以使用以下机制从 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);
    }
}

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

以下是我用来写入事件日志的代码:(EventLog 应用程序设置与源和名称相同)

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

【问题讨论】:

    标签: windows-services event-log


    【解决方案1】:

    似乎重新启动我的机器已经解决了这个问题。我还不确定为什么,但我会假设事件查看器机制进入了某种奇怪的状态。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-12
      • 2015-11-30
      相关资源
      最近更新 更多