Skip to content

Commit 5e359d9

Browse files
authored
Merge pull request #101 from nblumhardt/provider-name
UseSerilog() goodness
2 parents d74400f + 3f69691 commit 5e359d9

19 files changed

+233
-184
lines changed

samples/SimpleWebAPISample/Program.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

samples/SimpleWebAPISample/README.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

samples/SimpleWebAPISample/SimpleWebAPISample.csproj

Lines changed: 0 additions & 16 deletions
This file was deleted.

samples/SimpleWebAPISample/Startup.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

samples/SimpleWebAPISample/appsettings.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

samples/SimpleWebAPISample/Controllers/ScopesController.cs renamed to samples/SimpleWebSample/Controllers/ScopesController.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
using System;
21
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
52
using Microsoft.AspNetCore.Mvc;
6-
using Serilog;
73
using Microsoft.Extensions.Logging;
84

9-
namespace SimpleWebAPISample.Controllers
5+
namespace SimpleWebSample.Controllers
106
{
117
[Route("api/[controller]")]
128
public class ScopesController : Controller

samples/SimpleWebAPISample/Controllers/ValuesController.cs renamed to samples/SimpleWebSample/Controllers/ValuesController.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
1+
using System.Collections.Generic;
52
using Microsoft.AspNetCore.Mvc;
63
using Serilog;
74

8-
namespace SimpleWebAPISample.Controllers
5+
namespace SimpleWebSample.Controllers
96
{
107
[Route("api/[controller]")]
118
public class ValuesController : Controller

samples/SimpleWebSample/Program.cs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,53 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore;
73
using Microsoft.AspNetCore.Hosting;
84
using Microsoft.Extensions.Configuration;
9-
using Microsoft.Extensions.Logging;
10-
115
using Serilog;
126

137
namespace SimpleWebSample
148
{
159
public class Program
1610
{
17-
public static void Main(string[] args)
11+
public static int Main(string[] args)
1812
{
13+
var configuration = new ConfigurationBuilder()
14+
.SetBasePath(Directory.GetCurrentDirectory())
15+
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
16+
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: true)
17+
.Build();
18+
1919
Log.Logger = new LoggerConfiguration()
20+
.ReadFrom.Configuration(configuration)
2021
.Enrich.FromLogContext()
21-
.WriteTo.LiterateConsole()
22+
.WriteTo.Console()
2223
.CreateLogger();
23-
24-
Log.Information("Getting the motors running...");
2524

26-
BuildWebHost(args).Run();
27-
}
25+
try
26+
{
27+
Log.Information("Getting the motors running...");
2828

29-
public static IWebHost BuildWebHost(string[] args) =>
30-
WebHost.CreateDefaultBuilder(args)
31-
.UseStartup<Startup>()
32-
.ConfigureLogging(log =>
33-
{
34-
log.SetMinimumLevel(LogLevel.Information);
35-
log.AddSerilog(logger: Log.Logger, dispose: true);
36-
})
37-
.Build();
29+
var host = new WebHostBuilder()
30+
.UseKestrel()
31+
.UseContentRoot(Directory.GetCurrentDirectory())
32+
.UseIISIntegration()
33+
.UseStartup<Startup>()
34+
.UseConfiguration(configuration)
35+
.UseSerilog()
36+
.Build();
37+
38+
host.Run();
39+
40+
return 0;
41+
}
42+
catch (Exception ex)
43+
{
44+
Log.Fatal(ex, "Host terminated unexpectedly");
45+
return 1;
46+
}
47+
finally
48+
{
49+
Log.CloseAndFlush();
50+
}
51+
}
3852
}
3953
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication": false,
4+
"anonymousAuthentication": true,
5+
"iisExpress": {
6+
"applicationUrl": "http://localhost:51965/",
7+
"sslPort": 0
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName": "IISExpress",
13+
"launchBrowser": true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT": "Development"
16+
}
17+
},
18+
"SimpleWebSample": {
19+
"commandName": "Project",
20+
"launchBrowser": true,
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development"
23+
},
24+
"applicationUrl": "http://localhost:51966/"
25+
}
26+
}
27+
}

samples/SimpleWebSample/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The project was created with the following steps.
66
```
77
dotnet new web
88
dotnet add package Serilog.Extensions.Logging
9-
dotnet add package Serilog.Sinks.Literate
9+
dotnet add package Serilog.Sinks.Console
1010
```
1111

1212
* Extend the logging to include Serilog. See `Program.cs`
@@ -17,4 +17,4 @@ dotnet add package Serilog.Sinks.Literate
1717
})
1818
```
1919

20-
* Logging can then used directly to Serilog or via the `Microsoft.Extensions.Logging` pipeline.
20+
* Logging can then used directly to Serilog or via the `Microsoft.Extensions.Logging` pipeline.

0 commit comments

Comments
 (0)