Skip to content

Commit e129744

Browse files
committed
Update README.md
1 parent 36328ca commit e129744

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

README.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
1-
# serilog-framework-logging
2-
Serilog provider for Microsoft.Framework.Logging
1+
# Serilog.Framework.Logging
2+
3+
A serilog provider for [Microsoft.Framework.Logging](https://www.nuget.org/packages/Microsoft.Framework.Logging), the logging subsystem used by ASP.NET 5.
4+
5+
This package routes ASP.NET log messages through Serilog, so you can get information about ASP.NET's internal operations logged to the same Serilog sinks as your application events.
6+
7+
### Instructions
8+
9+
**First**, install the _Serilog.Framework.Logging_ [NuGet package](https://www.nuget.org/packages/Serilog.Framework.Logging) into your web or console app.
10+
11+
**Next**, in your application's `Startup` method, configure Serilog first:
12+
13+
```csharp
14+
using Serilog;
15+
16+
public class Startup
17+
{
18+
public Startup(IHostingEnvironment env)
19+
{
20+
Log.Logger = new LoggerConfiguration()
21+
#if DNXCORE50
22+
.WriteTo.TextWriter(Console.Out)
23+
#else
24+
.WriteTo.Trace()
25+
#endif
26+
.CreateLogger();
27+
28+
// Other startup code
29+
```
30+
31+
The conditional compilation (`#if`) is necessary if you're targeting the CoreCLR runtime, for which there are currenlty few Serilog sinks. If you're targeting the full .NET framework you can just use `.WriteTo.Trace()`, or any other available sink.
32+
33+
**Finally**, in your `Startup` class's `Configure()` method, call `UseSerilog()` on the provided `loggerFactory`.
34+
35+
```csharp
36+
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
37+
{
38+
loggerfactory.AddSerilog();
39+
```
40+
41+
That's it!
42+
43+
### Levels
44+
45+
If you want to get more information from the log you'll need to bump up the level.
46+
47+
Two things:
48+
49+
* You need to set `MinimumLevel` on **both** the Serilog `LoggerConfiguration` and the `ILoggerFactory`
50+
* Serilog and ASP.NET assign different priorities to the `Debug` and `Trace` levels; Serilog's `Debug` is ASP.NET's `Trace`, and vice-versa

0 commit comments

Comments
 (0)