Skip to content

Commit e68cf8d

Browse files
committed
Include Debug sink and note this in README; includes console, file, and JSON support; fixes #107
1 parent 90452d9 commit e68cf8d

File tree

6 files changed

+12
-17
lines changed

6 files changed

+12
-17
lines changed

README.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ With _Serilog.AspNetCore_ installed and configured, you can write log messages d
66

77
### Instructions
88

9-
**First**, install the _Serilog.AspNetCore_ [NuGet package](https://www.nuget.org/packages/Serilog.AspNetCore) into your app. You will need a way to view the log messages - _Serilog.Sinks.Console_ writes these to the console; there are [many more sinks available](https://www.nuget.org/packages?q=Tags%3A%22serilog%22) on NuGet.
9+
**First**, install the _Serilog.AspNetCore_ [NuGet package](https://www.nuget.org/packages/Serilog.AspNetCore) into your app.
1010

1111
```shell
1212
dotnet add package Serilog.AspNetCore
13-
dotnet add package Serilog.Sinks.Console
1413
```
1514

1615
**Next**, in your application's _Program.cs_ file, configure Serilog first. A `try`/`catch` block will ensure any configuration issues are appropriately logged:
@@ -79,7 +78,7 @@ That's it! With the level bumped up a little you will see log output resembling:
7978
[22:14:45.741 DBG] Handled. Status code: 304 File: /css/site.css
8079
```
8180

82-
Tip: to see Serilog output in the Visual Studio output window when running under IIS, select _ASP.NET Core Web Server_ from the _Show output from_ drop-down list.
81+
Tip: to see Serilog output in the Visual Studio output window when running under IIS, either select _ASP.NET Core Web Server_ from the _Show output from_ drop-down list, or replace `WriteTo.Console()` in the logger configuration with `WriteTo.Debug()`.
8382

8483
A more complete example, showing _appsettings.json_ configuration, can be found in [the sample project here](https://github.com/serilog/serilog-aspnetcore/tree/dev/samples/EarlyInitializationSample).
8584

@@ -162,17 +161,16 @@ This pattern has the advantage of reducing the number of log events that need to
162161

163162
### Inline initialization
164163

165-
You can alternatively configure Serilog inline, in `BulidWebHost()`, using a delegate as shown below:
164+
You can alternatively configure Serilog inline, in `BuildWebHost()`, using a delegate as shown below:
166165

167166
```csharp
168-
// dotnet add package Serilog.Settings.Configuration
169167
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
170168
.ReadFrom.Configuration(hostingContext.Configuration)
171169
.Enrich.FromLogContext()
172170
.WriteTo.Console())
173171
```
174172

175-
This has the advantage of making the `hostingContext`'s `Configuration` object available for configuration of the logger, but at the expense of recording `Exception`s raised earlier in program startup.
173+
This has the advantage of making the `hostingContext`'s `Configuration` object available for [configuration of the logger](https://github.com/serilog/serilog-settings-configuration), but at the expense of losing `Exception`s raised earlier in program startup.
176174

177175
If this method is used, `Log.Logger` is assigned implicitly, and closed when the app is shut down.
178176

@@ -219,13 +217,7 @@ If [inline initialization](#inline-initialization) is used, providers can be ena
219217

220218
### Writing to the Azure Diagnostics Log Stream
221219

222-
The Azure Diagnostic Log Stream ships events from any files in the `D:\home\LogFiles\` folder. To enable this for your app, first install the _Serilog.Sinks.File_ package:
223-
224-
```powershell
225-
Install-Package Serilog.Sinks.File
226-
```
227-
228-
Then add a file sink to your `LoggerConfiguration`, taking care to set the `shared` and `flushToDiskInterval` parameters:
220+
The Azure Diagnostic Log Stream ships events from any files in the `D:\home\LogFiles\` folder. To enable this for your app, add a file sink to your `LoggerConfiguration`, taking care to set the `shared` and `flushToDiskInterval` parameters:
229221

230222
```csharp
231223
public static int Main(string[] args)

samples/EarlyInitializationSample/EarlyInitializationSample.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.AspNetCore.App" />
1414
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
15-
<PackageReference Include="Serilog.Sinks.Console" Version="3.0.1" />
16-
<PackageReference Include="Serilog.Settings.Configuration" Version="2.4.0" />
1715
</ItemGroup>
1816

1917
</Project>

samples/EarlyInitializationSample/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static int Main(string[] args)
2121
Log.Logger = new LoggerConfiguration()
2222
.ReadFrom.Configuration(Configuration)
2323
.Enrich.FromLogContext()
24+
.WriteTo.Debug()
2425
.WriteTo.Console(
2526
// {Properties:j} added:
2627
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} " +

samples/InlineInitializationSample/InlineInitializationSample.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
<ItemGroup>
1313
<PackageReference Include="Microsoft.AspNetCore.App" />
1414
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
15-
<PackageReference Include="Serilog.Sinks.Console" Version="3.0.1" />
16-
<PackageReference Include="Serilog.Settings.Configuration" Version="2.4.0" />
1715
</ItemGroup>
1816

1917
</Project>

samples/InlineInitializationSample/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
1717
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
1818
.ReadFrom.Configuration(hostingContext.Configuration)
1919
.Enrich.FromLogContext()
20+
.WriteTo.Debug()
2021
.WriteTo.Console(
2122
// {Properties:j} added:
2223
outputTemplate: "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} " +

src/Serilog.AspNetCore/Serilog.AspNetCore.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
<PackageReference Include="Serilog" Version="2.8.0" />
2727
<PackageReference Include="Serilog.Extensions.Hosting" Version="3.0.0-dev-00019" />
2828
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.0-*" />
29+
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
30+
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
31+
<PackageReference Include="Serilog.Sinks.Debug" Version="1.0.1" />
32+
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
33+
<PackageReference Include="Serilog.Formatting.Compact" Version="1.0.0" />
2934
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.0.0" />
3035
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
3136
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />

0 commit comments

Comments
 (0)