无法使用Serilog在事件日志中关联事件ID

时间:2018-05-31 03:41:27

标签: serilog

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

我的问题是我在我的代码中说了一些Logging Events但是在查看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;
}

2 个答案:

答案 0 :(得分:1)

Serilog Windows Event Logger是开源的。我从来没有做过你所要求的,但我的回答只是基于查看源代码。如果您对如何使用开源库执行某些操作有疑问,那么您只需查看代码即可。

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

div {
  display: inline;
  padding-bottom: 5px;
  position: relative
}

div:hover {
  cursor: pointer;
}
div::after {
  content:'';
  position: absolute;
  height: 1px;
  left: 0;
  right: 0;
  bottom:0;
  display: block;
  background-color: black;
  transition: transform 0.3s ease-in-out;
}
div:hover::after {
  transform: translateY(-3px);
}

答案 1 :(得分:0)

补充@mason答案,这是从appsettings.json配置它的方法:

{
 "Serilog": {
  "WriteTo": [
    {
      "Name": "EventLog",
      "Args": {
        "source": "your source name",
        "eventIdProvider": "namespace.class, assembly"
      }
    }
  ]
 }
}

例如

{
 "Serilog": {
  "WriteTo": [
    {
      "Name": "EventLog",
      "Args": {
        "source": "MyApp",
        "eventIdProvider": "MyApp.MyEventIdProvider, MyApp"
      }
    }
  ]
 }
}
相关问题