c# - Windows 服务输出未显示在事件日志中

标签 c# windows windows-services event-log windows-7-x64

我正在尝试关注这个 walkthrough .

我使用的是 Visual Studio 2010 Premium。

我在服务器资源管理器或事件查看器中看到的唯一事件是“服务已成功启动”。和“服务已成功停止。”

这是服务代码:

namespace MyNewService
{
    public partial class MyNewService : ServiceBase
    {
        public MyNewService()
        {
            InitializeComponent();
            if (!EventLog.SourceExists("MySource"))
            {
                EventLog.CreateEventSource("MySource", "MyNewLog");
            }
            eventLog1.Source = "MySource";
            eventLog1.Log = "MyNewLog";
        }

        protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("In OnStart");
        }

        protected override void OnStop()
        {
            eventLog1.WriteEntry("In onStop.");
        }
    }
}

最佳答案

我在 Win 7 64 上使用 Visual Studio 2010 Professional 时遇到了同样的问题。我新编译的服务是使用以管理员身份运行的 InstallUtil.exe 安装的。它正确启动和停止。没有异常,但没有刷新事件查看器显示新的事件日志。 Fran71 的建议对我有用:我关闭了事件查看器并重新打开。瞧,新创建的应用程序日志文件出现了。

关于c# - Windows 服务输出未显示在事件日志中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7535168/

相关文章:

c# - 如何在 azure 中设置安全 Web 套接字

c# - 进程和可执行文件名

c# - 启动一个在我的 Windows 服务中不起作用的进程

c# - 是什么污染了这个 switch 语句?

c# - 如何将作为参数传递的 KeyValuePair 转换为 Command_Executed?

外部 dll 中的 c#/wpf OpenMP

windows - Dev-C++为错误版本的Windows创建EXE?

windows - 在 Spotify Desktop 中将歌曲添加到播放队列

windows - 如何在 localhost Windows 上释放端口 80?

c# - 如何找到windows服务exe路径