只有自定义事件才会使用 Serilog 记录两次

发布于 2025-01-13 00:37:05 字数 1062 浏览 6 评论 0原文

我有一个实现 Serilog 的自定义记录器。跟踪记录一次,但事件记录两次。

下面是 host.json:

{
"version": "2.0",
"logging": {
    "applicationInsights": {
        "samplingSettings": {
            "isEnabled": true,
            "excludedTypes": "Request"
        }
    }
}

}

Appsettings:

    {
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "APPINSIGHTS_INSTRUMENTATIONKEY": "abcdef-ghi-49f9-bd20-xxxxxxxxxxx"
  }
}

EventLogger 创建如下:

EventLogger = new LoggerConfiguration()
             .ReadFrom.AppSettings()
             .Enrich.FromLogContext()
             .WriteTo
             .ApplicationInsights(this.TelemetryConfiguration.InstrumentationKey, TelemetryConverter.Events).CreateLogger();

问题仅在于自定义事件。对于为什么会发生这种情况有什么想法吗?

在此处输入图像描述

I have a custom logger which implements serilog. Trace are getting logged once but the events are getting logged twice.

Below is the host.json:

{
"version": "2.0",
"logging": {
    "applicationInsights": {
        "samplingSettings": {
            "isEnabled": true,
            "excludedTypes": "Request"
        }
    }
}

}

Appsettings:

    {
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "APPINSIGHTS_INSTRUMENTATIONKEY": "abcdef-ghi-49f9-bd20-xxxxxxxxxxx"
  }
}

EventLogger is created as below:

EventLogger = new LoggerConfiguration()
             .ReadFrom.AppSettings()
             .Enrich.FromLogContext()
             .WriteTo
             .ApplicationInsights(this.TelemetryConfiguration.InstrumentationKey, TelemetryConverter.Events).CreateLogger();

The problem is just with custom events.Any thoughts on why this can happen?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文