NetPro.Serilog 6.0.16

dotnet add package NetPro.Serilog --version 6.0.16                
NuGet\Install-Package NetPro.Serilog -Version 6.0.16                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetPro.Serilog" Version="6.0.16" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetPro.Serilog --version 6.0.16                
#r "nuget: NetPro.Serilog, 6.0.16"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetPro.Serilog as a Cake Addin
#addin nuget:?package=NetPro.Serilog&version=6.0.16

// Install NetPro.Serilog as a Cake Tool
#tool nuget:?package=NetPro.Serilog&version=6.0.16                

NetPro.Serilog

NuGet

使用

依赖NetPro.Web.Api组件的模式

1、安装引用

NetPro.Serilog NuGet(已包含文件写入能力)

Serilog.Sinks.Async NuGet(异步写入能力)

如需要写入Elasticsearch,安装以下Nuget包即可

Serilog.Sinks.ElasticSearch NuGet

2、增加配置

//日志相关配置 Information  Error
{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "Microsoft": "Debug",
      "Microsoft.Hosting.Lifetime": "Debug"
    }
  },
  "Serilog": {
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Default": "Information",
        "Microsoft": "Information",
        "System": "Information",
        "System.Net.Http.HttpClient": "Information",
        "Microsoft.Hosting.Lifetime": "Information"
      }
    },
    "WriteTo:Async": {
      "Name": "Async",
      "Args": {
        "configure": [
          {
            "Name": "Console"
          }
          ,{
            "Name": "File",
            "Args": {
              "path": "Logs/.txt",
              "rollingInterval": "Day",
              "retainedFileCountLimit": "31", //Number of retained files by default 31
              "retainedFileTimeLimit": "10.00:00:00", //Deletes files older than 10 days
              "outputTemplate": "{Timestamp:o} [{Level:u3}] ({Application}/{MachineName}/{ThreadId}) {Message}{NewLine}{Exception}"
            }
          },          
          {
            "Name": "Elasticsearch",
            "Args": {
              "nodeUris": "http://elasticsearch.com:9200",
              "indexFormat": "xxxapi-{0:yyyy.MM}",
              "autoRegisterTemplate": true,
              "connectionGlobalHeaders": "Authorization=ApiKey XzVPaDFIOEJNNUduR1FGWFdiWlc6Sms5ajFUNHJTWDJ5VzEtOG4zSllsdw=="
            }
          }
        ]
      }
    },
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
    "Properties": {
      "Application": "XXX"
    }
  }
}

纯净模式下不依赖NetPro.Web.Api模式

1、安装引用 NuGet Nuget包

2、 注册初始化

public void Configure(IApplicationBuilder application, IWebHostEnvironment env)
{
    application.UseSerilogRequestLogging();
}

public void ConfigureServices(IServiceCollection services, IConfiguration configuration = null)
{
            Log.Logger = new LoggerConfiguration()
                                .ReadFrom.Configuration(configuration)
                                .CreateLogger();

            // Reference to https://github.com/serilog/serilog-aspnetcore/blob/dev/src/Serilog.AspNetCore/SerilogWebHostBuilderExtensions.cs
            services.AddSingleton<ILoggerFactory>(services => new SerilogLoggerFactory());

            // Registered to provide two services...
            var diagnosticContext = new DiagnosticContext(null);

            // Consumed by e.g. middleware
            services.AddSingleton(diagnosticContext);

            // Consumed by user code
            services.AddSingleton<IDiagnosticContext>(diagnosticContext);
}

3、 配置

//日志相关配置 Information  Error
{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "Microsoft": "Debug",
      "Microsoft.Hosting.Lifetime": "Debug"
    }
  },
  "Serilog": {
    "MinimumLevel": {
      "Default": "Debug",
      "Override": {
        "Default": "Information",
        "Microsoft": "Information",
        "System": "Information",
        "System.Net.Http.HttpClient": "Information",
        "Microsoft.Hosting.Lifetime": "Information"
      }
    },
    "WriteTo:Async": {
      "Name": "Async",
      "Args": {
        "configure": [
          {
            "Name": "Console"
          }
          ,{
            "Name": "File",
            "Args": {
              "path": "Logs/.txt",
              "rollingInterval": "Day",
              "retainedFileCountLimit": "31", //Number of retained files by default 31
              "retainedFileTimeLimit": "10.00:00:00", //Deletes files older than 10 days
              "outputTemplate": "{Timestamp:o} [{Level:u3}] ({Application}/{MachineName}/{ThreadId}) {Message}{NewLine}{Exception}"
            }
          },          
          {
            "Name": "Elasticsearch",
            "Args": {
              "nodeUris": "http://elasticsearch.com:9200",
              "indexFormat": "xxxapi-{0:yyyy.MM}",
              "autoRegisterTemplate": true,
              "connectionGlobalHeaders": "Authorization=ApiKey XzVPaDFIOEJNNUduR1FGWFdiWlc6Sms5ajFUNHJTWDJ5VzEtOG4zSllsdw=="
            }
          }
        ]
      }
    },
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
    "Properties": {
      "Application": "XXX"
    }
  }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on NetPro.Serilog:

Repository Stars
LeonKou/NetPro
🌈An enhanced version with clean architecture of asp.netcore,efficiently manage startup,Support for netcore3.1/6.0
Version Downloads Last updated
6.0.16 307 7/24/2023
6.0.15 738 7/19/2022
6.0.14 457 7/10/2022
6.0.13 498 6/15/2022
6.0.12 420 6/15/2022
6.0.11 390 6/15/2022
6.0.10 424 6/11/2022
6.0.9 436 6/8/2022
6.0.8 489 5/26/2022
6.0.8-beta.3 501 5/24/2022
6.0.8-beta.2 116 5/24/2022
6.0.8-beta.1 111 5/24/2022