From 1b9e1250103982a37ec63f7085326b4dcf039ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Mon, 30 Aug 2021 09:16:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8serilog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub/FastGithub.csproj | 6 ++++++ FastGithub/Program.cs | 8 ++++++++ FastGithub/appsettings.json | 14 ++++++++------ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/FastGithub/FastGithub.csproj b/FastGithub/FastGithub.csproj index eae11ca..c6d63a6 100644 --- a/FastGithub/FastGithub.csproj +++ b/FastGithub/FastGithub.csproj @@ -20,6 +20,12 @@ + + + + + + PreserveNewest diff --git a/FastGithub/Program.cs b/FastGithub/Program.cs index 26449db..484e2ce 100644 --- a/FastGithub/Program.cs +++ b/FastGithub/Program.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; +using Serilog; using System; using System.IO; @@ -55,6 +56,13 @@ namespace FastGithub kestrel.ListenHttpReverseProxy(); kestrel.ListenGithubSshProxy(); }); + webBuilder.UseSerilog((hosting, logger) => + { + logger + .ReadFrom.Configuration(hosting.Configuration) + .Enrich.FromLogContext() + .WriteTo.Console(outputTemplate: "{Timestamp:O} [{Level:u3}]{NewLine}{SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}"); + }); }); } } diff --git a/FastGithub/appsettings.json b/FastGithub/appsettings.json index 8f8515d..60f4d4a 100644 --- a/FastGithub/appsettings.json +++ b/FastGithub/appsettings.json @@ -31,13 +31,15 @@ } } }, - "Logging": { - "LogLevel": { + "Serilog": { + "MinimumLevel": { "Default": "Information", - "Yarp": "Warning", - "System": "Warning", - "Microsoft": "Warning", - "Microsoft.AspNetCore.Server.Kestrel": "Error" + "Override": { + "Yarp": "Warning", + "System": "Warning", + "Microsoft": "Warning", + "Microsoft.AspNetCore.Server.Kestrel": "Error" + } } } }