写入事件日志 Windows 计划任务
我有一个控制台应用程序,它将通过计划任务运行,我想做的是将其写入 catch 块中的事件日志。 我尝试过使用
EventLog.WriteEntry("My App Name","Error Message - " ex.ToString() );
,但由于某种原因它没有写入错误。 难道我做错了什么?
谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要确保事件源存在,例如:
请参阅 https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlog.createeventsource?view=net-8.0
You need to make sure the event-source exists, e.g.:
See https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlog.createeventsource?view=net-8.0
需要注意的一件事是,调用 EventLog.CreateEventSource 时有时会出现轻微延迟,因此在创建后立即尝试访问创建的 EventSource 时应该注意这一点。
One thing to note is that there is sometimes a small delay when calling EventLog.CreateEventSource, so you should be aware of that when trying to access the created EventSource immediately after creation.
这段代码来自MSDN网站的C#,希望对你有帮助。
This code is from MSDN website in C#, I hope it help you.