gpt4 book ai didi

serilog - 无法使用 Serilog 关联事件日志中的事件 ID

转载 作者:行者123 更新时间:2023-12-02 03:34:40 25 4
gpt4 key购买 nike

我使用 Serilog 作为 .NET 的库,它为文件、控制台和其他地方提供诊断日志记录。

我的问题是我在我的代码中声明了一些日志记录事件,但是在查看 Windows 事件查看器时,分配给我的日志的事件 ID 在事件查看器中没有关联。关于如何修改以添加事件 ID 的任何想法?

记录事件代码

public class LoggingEvents
{
//info
public const int GENERATE_INDEXPAGE = 2000;
public const int ADMIN_ACCESS = 2001;
public const int ON_GET_REGISTRATION = 2002;
public const int ON_GET_APP_BY_KEY = 2003;
public const int ON_GET_BY_AIR_ID = 2004;
public const int ON_GET_USERS = 2005;
public const int ON_GET_GROUPS = 2006;
public const int ON_POST_APPLICATION = 2007;

//warning
public const int NO_ADMIN_ACCESS = 3000;
public const int INVALID_AIR_ID = 3001;

//error
public const int ERROR_POST_APPLICATION = 4000;
}

最佳答案

Serilog Windows Event Logger是开源的。我从来没有做过你问的事情,但我的回答只是基于查看源代码。如果您对如何使用开源库做某事有疑问,您只需查看代码即可。

添加事件日志接收器时,您需要做的就是创建一个 IEventIdProvider 的实例。然后注册。

public class MyEventIdProvider : IEventIdProvider
{
public ushort ComputeEventId(LogEvent logEvent)
{
//your implementation here
}
}

Log.Logger = new LoggerConfiguration()
.WriteTo.EventLog("Sample App",
manageEventSource: true,
eventIdProvider: new MyEventIdProvider())
.CreateLogger();

关于serilog - 无法使用 Serilog 关联事件日志中的事件 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50616296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com