-
Notifications
You must be signed in to change notification settings - Fork 104
UseSerilog() goodness #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a95aed3
Fixes #98 - UseSerilog() goodness
nblumhardt ca7806d
Bump minor version - new APIs
nblumhardt 5602d03
Merge samples, support environment name
nblumhardt 341c542
Trivial sample improvements
nblumhardt 3f69691
Namespace fix
nblumhardt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
|
||
using Serilog; | ||
|
||
namespace SimpleWebAPISample | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
public static int Main(string[] args) | ||
{ | ||
var configuration = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | ||
.Build(); | ||
|
||
Log.Logger = new LoggerConfiguration() | ||
.ReadFrom.Configuration(configuration) | ||
.Enrich.FromLogContext() | ||
.WriteTo.LiterateConsole() | ||
.WriteTo.Console() | ||
.CreateLogger(); | ||
|
||
Log.Information("Getting the motors running..."); | ||
|
||
BuildWebHost(args).Run(); | ||
} | ||
try | ||
{ | ||
Log.Information("Getting the motors running..."); | ||
|
||
public static IWebHost BuildWebHost(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>() | ||
.ConfigureLogging(log => | ||
{ | ||
log.SetMinimumLevel(LogLevel.Information); | ||
log.AddSerilog(logger: Log.Logger, dispose: true); | ||
}) | ||
.Build(); | ||
var host = WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>() | ||
.UseConfiguration(configuration) | ||
.UseSerilog() | ||
.Build(); | ||
|
||
host.Run(); | ||
|
||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "Unhandled exception"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:51968/", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"SimpleWebAPISample": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "http://localhost:51972/" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
|
||
using Serilog; | ||
|
||
namespace SimpleWebSample | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
public static int Main(string[] args) | ||
{ | ||
var configuration = new ConfigurationBuilder() | ||
.SetBasePath(Directory.GetCurrentDirectory()) | ||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | ||
.Build(); | ||
|
||
Log.Logger = new LoggerConfiguration() | ||
.ReadFrom.Configuration(configuration) | ||
.Enrich.FromLogContext() | ||
.WriteTo.LiterateConsole() | ||
.WriteTo.Console() | ||
.CreateLogger(); | ||
|
||
Log.Information("Getting the motors running..."); | ||
|
||
BuildWebHost(args).Run(); | ||
} | ||
try | ||
{ | ||
Log.Information("Getting the motors running..."); | ||
|
||
public static IWebHost BuildWebHost(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>() | ||
.ConfigureLogging(log => | ||
{ | ||
log.SetMinimumLevel(LogLevel.Information); | ||
log.AddSerilog(logger: Log.Logger, dispose: true); | ||
}) | ||
.Build(); | ||
var host = WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>() | ||
.UseConfiguration(configuration) | ||
.UseSerilog() | ||
.Build(); | ||
|
||
host.Run(); | ||
|
||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "Unhandled exception"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:51965/", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"SimpleWebSample": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "http://localhost:51966/" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"Logging": { | ||
"IncludeScopes": false, | ||
"LogLevel": { | ||
"Default": "Debug", | ||
"System": "Information", | ||
"Microsoft": "Information" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"Serilog": { | ||
"MinimumLevel": { | ||
"Default": "Debug", | ||
"Override": { | ||
"Microsoft": "Information", | ||
"System": "Warning" | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One slight annoyance here - any idea how to get the information about the hosting environment - Development, Production etc. - without resolving
IHostingEnvironment
from DI?