|
1 | | -# serilog-sinks-debug |
2 | | -Writes Serilog events to the debug output window |
| 1 | +# Serilog.Sinks.Debug [](https://ci.appveyor.com/project/serilog/serilog-sinks-debug) [](https://www.nuget.org/packages/Serilog.Sinks.Debug/) [](https://github.com/serilog/serilog/wiki) [](https://gitter.im/serilog/serilog) [](http://stackoverflow.com/questions/tagged/serilog) |
| 2 | + |
| 3 | +A Serilog sink that writes log events to the Visual Studio debug output window. |
| 4 | + |
| 5 | +### Getting started |
| 6 | + |
| 7 | +To use the sink, first install the [NuGet package](https://nuget.org/packages/serilog.sinks.debug): |
| 8 | + |
| 9 | +```powershell |
| 10 | +Install-Package Serilog.Sinks.Debug |
| 11 | +``` |
| 12 | + |
| 13 | +Then enable the sink using `WriteTo.Debug()`: |
| 14 | + |
| 15 | +```csharp |
| 16 | +Log.Logger = new LoggerConfiguration() |
| 17 | + .WriteTo.Debug() |
| 18 | + .CreateLogger(); |
| 19 | + |
| 20 | +Log.Information("Hello, world!"); |
| 21 | +``` |
| 22 | + |
| 23 | +Log events will be printed to the debug output: |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +### XML `<appSettings>` configuration |
| 28 | + |
| 29 | +To use the sink with the [Serilog.Settings.AppSettings](https://github.com/serilog/serilog-settings-appsettings) package, first install that package if you haven't already done so: |
| 30 | + |
| 31 | +```powershell |
| 32 | +Install-Package Serilog.Settings.AppSettings |
| 33 | +``` |
| 34 | + |
| 35 | +Instead of configuring the logger in code, call `ReadFrom.AppSettings()`: |
| 36 | + |
| 37 | +```csharp |
| 38 | +var log = new LoggerConfiguration() |
| 39 | + .ReadFrom.AppSettings() |
| 40 | + .CreateLogger(); |
| 41 | +``` |
| 42 | + |
| 43 | +In your application's `App.config` or `Web.config` file, specify the console sink assembly under the `<appSettings>` node: |
| 44 | + |
| 45 | +```xml |
| 46 | +<configuration> |
| 47 | + <appSettings> |
| 48 | + <add key="serilog:using:Debug" value="Serilog.Sinks.Debug" /> |
| 49 | + <add key="serilog:write-to:Debug" /> |
| 50 | +``` |
| 51 | + |
| 52 | +### JSON `appsettings.json` configuration |
| 53 | + |
| 54 | +To use the console sink with _Microsoft.Extensions.Configuration_, for example with ASP.NET Core or .NET Core, use the [Serilog.Settings.Configuration](https://github.com/serilog/serilog-settings-configuration) package. First install that package if you have not already done so: |
| 55 | + |
| 56 | +```powershell |
| 57 | +Install-Package Serilog.Settings.Configuration |
| 58 | +``` |
| 59 | + |
| 60 | +Instead of configuring the sink directly in code, call `ReadFrom.Configuration()`: |
| 61 | + |
| 62 | +```csharp |
| 63 | +var configuration = new ConfigurationBuilder() |
| 64 | + .AddJsonFile("appsettings.json") |
| 65 | + .Build(); |
| 66 | + |
| 67 | +var logger = new LoggerConfiguration() |
| 68 | + .ReadFrom.Configuration(configuration) |
| 69 | + .CreateLogger(); |
| 70 | +``` |
| 71 | + |
| 72 | +In your `appsettings.json` file, under the `Serilog` node, : |
| 73 | + |
| 74 | +```json |
| 75 | +{ |
| 76 | + "Serilog": { |
| 77 | + "WriteTo": ["Debug"] |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +_Copyright © 2017 Serilog Contributors - Provided under the [Apache License, Version 2.0](http://apache.org/licenses/LICENSE-2.0.html)._ |
0 commit comments