Skip to content

Commit 101ddef

Browse files
committed
improvements: minor logger improvements
1 parent 9ec1145 commit 101ddef

5 files changed

Lines changed: 18 additions & 18 deletions

File tree

ProjectTemplates/AspNetCore.WebApi/ReferenceProject/ReferenceProject/Middleware/ExceptionMiddleware.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Threading.Tasks;
55
using Microsoft.Extensions.Logging;
66
using Newtonsoft.Json;
7-
using Newtonsoft.Json.Serialization;
87
using Microsoft.AspNetCore.Hosting;
98
using ReferenceProject.Exceptions;
109

ProjectTemplates/AspNetCore.WebApi/ReferenceProject/ReferenceProject/Program.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
2222
{
2323
logging.ClearProviders();
2424

25+
/*
26+
* You can use a global logger as this, but I don't recommend this way
2527
Log.Logger = new LoggerConfiguration()
2628
.ReadFrom.Configuration(context.Configuration)
2729
.CreateLogger();
30+
*/
2831

29-
logging.AddSerilog();
32+
logging.AddSerilog(new LoggerConfiguration()
33+
.ReadFrom.Configuration(context.Configuration)
34+
.CreateLogger());
3035
})
3136
.ConfigureAppConfiguration(x =>
3237
{

ProjectTemplates/AspNetCore.WebApi/ReferenceProject/ReferenceProject/Startup.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,21 @@
1010
using Microsoft.AspNetCore.Mvc.Routing;
1111
using Microsoft.Extensions.Configuration;
1212
using Microsoft.Extensions.DependencyInjection;
13+
using Microsoft.Extensions.Logging;
1314
using Newtonsoft.Json;
1415
using Newtonsoft.Json.Serialization;
1516
using ReferenceProject.Middleware;
1617
using ReferenceProject.Modules;
17-
using Serilog;
1818

1919
namespace ReferenceProject
2020
{
2121
public class Startup
2222
{
23-
public Startup(IConfiguration configuration, IHostingEnvironment env)
23+
ILogger<Startup> Logger { get; }
24+
25+
public Startup(IConfiguration configuration, IHostingEnvironment env, ILogger<Startup> logger)
2426
{
27+
Logger = logger;
2528
Configuration = configuration;
2629

2730
var envPath = Path.Combine(env.ContentRootPath, ".env");
@@ -37,7 +40,6 @@ public Startup(IConfiguration configuration, IHostingEnvironment env)
3740
NullValueHandling = NullValueHandling.Ignore,
3841
DefaultValueHandling = DefaultValueHandling.Include,
3942
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
40-
//Formatting = Formatting.Indented,
4143
#if DEBUG
4244
Formatting = Formatting.Indented
4345
#else
@@ -116,7 +118,7 @@ public void Configure(IApplicationBuilder app/*, IHostingEnvironment env*/)
116118

117119
app.UseMvcWithDefaultRoute();
118120

119-
Log.Information("Server started");
121+
Logger.LogInformation("Server started");
120122
}
121123
}
122124
}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
{
2-
"Logging": {
3-
"LogLevel": {
2+
"Serilog": {
3+
"MinimumLevel": {
44
"Default": "Debug",
5-
"System": "Information",
6-
"Microsoft": "Information"
5+
"Override": {
6+
"Microsoft": "Debug",
7+
"System": "Debug"
8+
}
79
}
8-
},
9-
"Serilog": {
10-
"MinimumLevel": "Verbose"
1110
}
1211
}

ProjectTemplates/AspNetCore.WebApi/ReferenceProject/ReferenceProject/appsettings.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
{
2-
"Logging": {
3-
"LogLevel": {
4-
"Default": "Warning"
5-
}
6-
},
72
"Serilog": {
83
"MinimumLevel": {
94
"Default": "Warning",

0 commit comments

Comments
 (0)