Skip to content

Commit

Permalink
Updated example to make it clear that structured logging is not possi…
Browse files Browse the repository at this point in the history
…ble with current compiler (dotnet/roslyn#142).
  • Loading branch information
PawelGerr committed Feb 10, 2018
1 parent 4203596 commit 1e9f1c8
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Linq;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Core;
using Serilog.Events;

namespace Thinktecture.Extensions.Logging.Abstractions.Example
{
Expand All @@ -9,11 +12,12 @@ class Program
static void Main(string[] args)
{
var serilog = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();
.WriteTo.Console()
.WriteTo.Sink(new MySink())
.CreateLogger();
var logger = new LoggerFactory()
.AddSerilog(serilog)
.CreateLogger<Program>();
.AddSerilog(serilog)
.CreateLogger<Program>();

var a = "text";
var b = 42;
Expand All @@ -24,4 +28,21 @@ static void Main(string[] args)
Console.ReadLine();
}
}

internal class MySink : ILogEventSink
{
public void Emit(LogEvent logEvent)
{
Console.WriteLine();
Console.WriteLine($"Template: {logEvent.MessageTemplate.Text}");
Console.WriteLine("Properties:");

foreach (var kvp in logEvent.Properties)
{
// Issue: formattable string does not capture the names of the placeholders
// https://github.com/dotnet/roslyn/issues/142
Console.WriteLine($"\t{kvp.Key} = {kvp.Value}");
}
}
}
}

0 comments on commit 1e9f1c8

Please sign in to comment.