Write to EventLog in .Net Core

冷暖自知 提交于 2019-12-01 00:02:48

问题


I need a way to write to Windows' event viewer in my app that's using dnx. But, the EventLog class isn't available in the System.Diagnostics namespace so I'm stuck. Is there any other way to write to the EventViewer?


回答1:


Add from NuGet Microsoft.Extensions.Logging.EventLog Version 2.1.1

CM> Install-Package Microsoft.Extensions.Logging.EventLog -Version 2.1.1

Include the namespace Microsoft.Extensions.Logging.EventLog in the Program.cs file

This resolved my problem.




回答2:


Good news! EventLog is already ported to corefx and will be available in .NET Core 2.1.

Right now you can download a preview package System.Diagnostics.EventLog from their MyGet feed.




回答3:


it is available in 2.0 but you have to install the compatibility pack. https://github.com/dotnet/corefx/issues/25440

Here for more information: https://blogs.msdn.microsoft.com/dotnet/2017/11/16/announcing-the-windows-compatibility-pack-for-net-core/



来源:https://stackoverflow.com/questions/39131217/write-to-eventlog-in-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!