WindPayer.Logging 1.0.9

安装

dotnet add package WindPayer.Logging

快速开始

// Program.cs
using WindPayer.Logging;
builder.UseWindpayerLogging();

// 正常的logger调用
// 文本信息推荐使用占位符形式,框架会自动解析出额外的结构化,以下写法会额外输出字段【id】
logger.LogInformation("这是一条日志 {id}", id);
// 不推荐写法
logger.LogInformation($"这是一条日志 {id}");

// 自定义额外信息,单次
_logger.LogCtxInformation(new { bid = 20251212 }, "这是一条日志 {id}", id);

// 范围生效
using(_logger.WithCtx(new { userId = 10001 })
{
    // 业务代码
    _logger.LogCtxInformation(new { bid = 20251212 }, "这是一条日志 {id}", id);
    // 业务代码
    _logger.LogCtxInformation(new { orderId = "123456" }, "这是一条日志 {id}", id);
    // 业务代码
}

// 不推荐直接使用 _logger.WithCtx(), 因为会在调用后整个请求生命周期内生效

配置

在 appsettings.json 中添加如下配置

  "WindpayerLogging": {
    "LogLevel": "Information",              //日志级别
    "ServiceName": "Notification",          //服务名称  
    "EnableConsole": true,
    "EnableOtlp": false,
    "EnableTracing": false,
    "OtlpEndpoint": "http://localhost:4317",// OTLP 地址,EnableOtlp,EnableTracing为 true 时生效
    "OtlpAuthKey": "dXNlcjE6T20xNWNHRnpjMWQ=",   // OTLP key,base64 编码的 "用户名:密码"
    // 请求日志记录配置
    "RequestLogging": {
      "SlowRequestThresholdMs": 1000,
      "GetRequestSamplingRate": 0.1,
      "LogPostRequestsAll": true,
      "LogUnsampledSlowOrErrorRequests": true,
      "MaxRequestBodyLogLength": 10000,
      "MaxResponseBodyLogLength": 10000,      
      "IgnoredPaths": [
        "/health",
        "/healthz",
        "/ready",
        "/live",
        "/metrics"
      ]
    }
  },

Showing the top 20 packages that depend on WindPayer.Logging.

Packages Downloads
WindPayer.Logging.AspNetCore
提供 WindPayer.Logging 的 ASP.NET Core 快速配置扩展,包含 IStartupFilter 自动注入请求日志中间件及 WebApplicationBuilder / IHostBuilder 快速配置。
11
WindPayer.Logging.AspNetCore
提供 WindPayer.Logging 的 ASP.NET Core 快速配置扩展,包含 IStartupFilter 自动注入请求日志中间件及 WebApplicationBuilder / IHostBuilder 快速配置。
6
WindPayer.Logging.AspNetCore
提供 WindPayer.Logging 的 ASP.NET Core 快速配置扩展,包含 IStartupFilter 自动注入请求日志中间件及 WebApplicationBuilder / IHostBuilder 快速配置。
4

.NET 7.0

.NET 8.0

Version Downloads Last updated
1.1.13 7 07/16/2026
1.1.12 4 07/16/2026
1.1.11 4 07/15/2026
1.1.10 7 06/15/2026
1.1.9 5 06/15/2026
1.1.8 10 06/08/2026
1.1.7 11 06/05/2026
1.1.6 5 06/05/2026
1.1.5 6 06/05/2026
1.1.4 6 06/05/2026
1.1.3 6 06/03/2026
1.1.2 11 05/11/2026
1.1.1 9 04/30/2026
1.1.0 7 04/30/2026
1.0.9 6 04/24/2026
1.0.8 11 04/23/2026
1.0.7 8 04/23/2026
1.0.6 8 04/23/2026
1.0.5 6 03/26/2026
1.0.4 848 11/06/2025
1.0.3 845 10/29/2025
1.0.2 847 10/29/2025
1.0.1 851 10/29/2025
1.0.0 852 10/29/2025