Skip to content

serilog/serilog-sinks-debug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4bff92c · Jun 14, 2024

History

39 Commits
Jan 12, 2021
Jun 13, 2024
Jun 14, 2024
Jun 13, 2024
Aug 27, 2017
Aug 27, 2017
Aug 27, 2017
Aug 27, 2017
Jun 14, 2024
Aug 27, 2017
Aug 27, 2017
Jun 14, 2024
Jun 14, 2024
Aug 28, 2017
Aug 27, 2017

Repository files navigation

Serilog.Sinks.Debug Build status NuGet Version Help

A Serilog sink that writes log events to the Visual Studio debug output window.

Getting started

To use the sink, first install the NuGet package:

dotnet add package Serilog.Sinks.Debug

Then enable the sink using WriteTo.Debug():

Log.Logger = new LoggerConfiguration()
    .WriteTo.Debug()
    .CreateLogger();
    
Log.Information("Hello, world!");

Log events will be printed to the debug output:

Debug Output

XML <appSettings> configuration

To use the sink with the Serilog.Settings.AppSettings package, first install that package if you haven't already done so:

Install-Package Serilog.Settings.AppSettings

Instead of configuring the logger in code, call ReadFrom.AppSettings():

var log = new LoggerConfiguration()
    .ReadFrom.AppSettings()
    .CreateLogger();

In your application's App.config or Web.config file, specify the console sink assembly under the <appSettings> node:

<configuration>
  <appSettings>
    <add key="serilog:using:Debug" value="Serilog.Sinks.Debug" />
    <add key="serilog:write-to:Debug" />

JSON appsettings.json configuration

To use the console sink with Microsoft.Extensions.Configuration, for example with ASP.NET Core or .NET Core, use the Serilog.Settings.Configuration package. First install that package if you have not already done so:

Install-Package Serilog.Settings.Configuration

Instead of configuring the sink directly in code, call ReadFrom.Configuration():

var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .Build();

var logger = new LoggerConfiguration()
    .ReadFrom.Configuration(configuration)
    .CreateLogger();

In your appsettings.json file, under the Serilog node, :

{
  "Serilog": {
    "WriteTo": ["Debug"]
  }
}

Copyright © 2017 Serilog Contributors - Provided under the Apache License, Version 2.0.