Skip to content

Commit 618600a

Browse files
authored
Merge pull request #110 from serilog/batteries-included-2
Dependency and README updates
2 parents bcc787a + f2de594 commit 618600a

File tree

6 files changed

+24
-19
lines changed

6 files changed

+24
-19
lines changed

README.md

Lines changed: 14 additions & 12 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,9 +78,9 @@ 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

84-
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).
83+
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

8685
### Request logging <sup>`3.0.0-*`</sup>
8786

@@ -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

@@ -217,15 +215,19 @@ If [inline initialization](#inline-initialization) is used, providers can be ena
217215
writeToProviders: true)
218216
```
219217

220-
### Writing to the Azure Diagnostics Log Stream
218+
### JSON output
219+
220+
The `Console()`, `Debug()`, and `File()` sinks all support JSON-formatted output natively, via the included _Serilog.Formatting.Compact_ package.
221221

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:
222+
To write newline-delimited JSON, pass a `CompactJsonFormatter` or `RenderedCompactJsonFormatter` to the sink configuration method:
223223

224-
```powershell
225-
Install-Package Serilog.Sinks.File
224+
```csharp
225+
.WriteTo.Console(new RenderedCompactJsonFormatter())
226226
```
227227

228-
Then add a file sink to your `LoggerConfiguration`, taking care to set the `shared` and `flushToDiskInterval` parameters:
228+
### Writing to the Azure Diagnostics Log Stream
229+
230+
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:
229231

230232
```csharp
231233
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.1.1" />
16-
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.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.1.1" />
16-
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>Serilog support for ASP.NET Core logging</Description>
@@ -11,7 +11,7 @@
1111
<SignAssembly>true</SignAssembly>
1212
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
1313
<PackageTags>serilog;aspnet;aspnetcore</PackageTags>
14-
<PackageIconUrl>http://serilog.net/images/serilog-extension-nuget.png</PackageIconUrl>
14+
<PackageIconUrl>https://serilog.net/images/serilog-extension-nuget.png</PackageIconUrl>
1515
<PackageProjectUrl>https://github.com/serilog/serilog-aspnetcore</PackageProjectUrl>
1616
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1717
<RepositoryUrl>https://github.com/serilog/serilog-aspnetcore</RepositoryUrl>
@@ -22,7 +22,12 @@
2222

2323
<ItemGroup>
2424
<PackageReference Include="Serilog" Version="2.8.0" />
25-
<PackageReference Include="Serilog.Extensions.Hosting" Version="3.0.0-dev-00019" />
25+
<PackageReference Include="Serilog.Extensions.Hosting" Version="3.0.0" />
26+
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
27+
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
28+
<PackageReference Include="Serilog.Sinks.Debug" Version="1.0.1" />
29+
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
30+
<PackageReference Include="Serilog.Formatting.Compact" Version="1.0.0" />
2631
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.0.0" />
2732
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
2833
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0" />

0 commit comments

Comments
 (0)