From 8053baabd36aa370dbf01f7f6e10496be6f50a42 Mon Sep 17 00:00:00 2001 From: wanggaofeng <15601716045@163.com> Date: Thu, 23 May 2024 20:30:10 +0800 Subject: [PATCH] =?UTF-8?q?Serilog=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HttpClientStudy.UnitTest.csproj | 20 +++++++++---------- .../HttpResponses/HttpResponseContentTest.cs | 8 +------- HttpClientStudy.UnitTest/startup.cs | 13 ++++++------ 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/HttpClientStudy.UnitTest/HttpClientStudy.UnitTest.csproj b/HttpClientStudy.UnitTest/HttpClientStudy.UnitTest.csproj index 0dbda1b..3eeb9c1 100644 --- a/HttpClientStudy.UnitTest/HttpClientStudy.UnitTest.csproj +++ b/HttpClientStudy.UnitTest/HttpClientStudy.UnitTest.csproj @@ -12,13 +12,13 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + @@ -27,19 +27,19 @@ - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/HttpClientStudy.UnitTest/HttpResponses/HttpResponseContentTest.cs b/HttpClientStudy.UnitTest/HttpResponses/HttpResponseContentTest.cs index 3ade0e0..e8107d5 100644 --- a/HttpClientStudy.UnitTest/HttpResponses/HttpResponseContentTest.cs +++ b/HttpClientStudy.UnitTest/HttpResponses/HttpResponseContentTest.cs @@ -20,15 +20,9 @@ namespace HttpClientStudy.UnitTest.HttpResponses { HttpClient client = new HttpClient(); - var content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(new { Name="sdfsdf"}), Encoding.UTF8, System.Net.Mime.MediaTypeNames.Application.Json); + var content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(new { Name="张三"}), Encoding.UTF8, System.Net.Mime.MediaTypeNames.Application.Json); client.PostAsync("http://www.baidu.com", content); } } - - public class Demo - { - public string Name { get; set; } - public string Description { get; set; } - } } diff --git a/HttpClientStudy.UnitTest/startup.cs b/HttpClientStudy.UnitTest/startup.cs index e7dcf3b..3604942 100644 --- a/HttpClientStudy.UnitTest/startup.cs +++ b/HttpClientStudy.UnitTest/startup.cs @@ -69,7 +69,12 @@ namespace HttpClientStudy.UnitTest }) .ConfigureTestServices(services => { - + services.AddSerilog((services, loggerConfiguration) => + { + loggerConfiguration + .WriteTo.File("logs\\log.txt", rollingInterval: RollingInterval.Day) + .WriteTo.Console(); + }); }) .UseStartup() ; @@ -93,12 +98,6 @@ namespace HttpClientStudy.UnitTest public void ConfigureServices(IServiceCollection services) { services.AddLogging(lb => lb.AddXunitOutput()); - services.AddSerilog((services, loggerConfiguration) => - { - loggerConfiguration - .WriteTo.File("log.txt", outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {SourceContext}: {Message:lj}{NewLine}{Exception}") - .WriteTo.Console(); - }); } public void Configure(IApplicationBuilder app)