-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated example to make it clear that structured logging is not possi…
…ble with current compiler (dotnet/roslyn#142).
- Loading branch information
Showing
5 changed files
with
43 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
[![Build status](https://ci.appveyor.com/api/projects/status/ys8hswkylkqbf734?svg=true)](https://ci.appveyor.com/project/PawelGerr/thinktecture-extensions-logging) | ||
|
||
[![Build status](https://ci.appveyor.com/api/projects/status/ys8hswkylkqbf734?svg=true)](https://ci.appveyor.com/project/PawelGerr/thinktecture-extensions-logging) | ||
|
||
Adds string interpolation support to [ILogger](https://www.nuget.org/packages/Microsoft.Extensions.Logging.Abstractions/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 38 additions & 18 deletions
56
examples/Thinktecture.Extensions.Logging.Abstractions.Example/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,47 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
using Serilog; | ||
using Serilog.Core; | ||
using Serilog.Events; | ||
|
||
namespace Thinktecture.Extensions.Logging.Abstractions.Example | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var serilog = new LoggerConfiguration() | ||
.WriteTo.Console() | ||
.CreateLogger(); | ||
var logger = new LoggerFactory() | ||
.AddSerilog(serilog) | ||
.CreateLogger<Program>(); | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
var serilog = new LoggerConfiguration() | ||
.WriteTo.Console() | ||
.WriteTo.Sink(new MySink()) | ||
.CreateLogger(); | ||
var logger = new LoggerFactory() | ||
.AddSerilog(serilog) | ||
.CreateLogger<Program>(); | ||
|
||
var a = "text"; | ||
var b = 42; | ||
logger.LogInformation((string)$"Using standard extension method: a = {a}, b = {b}"); | ||
logger.LogInformation($"Using new extension method: a = {a}, b = {b}"); | ||
var a = "text"; | ||
var b = 42; | ||
logger.LogInformation((string)$"Using standard extension method: a = {a}, b = {b}"); | ||
logger.LogInformation($"Using new extension method: a = {a}, b = {b}"); | ||
|
||
Console.WriteLine("Press ENTER to exit."); | ||
Console.ReadLine(); | ||
} | ||
} | ||
Console.WriteLine("Press ENTER to exit."); | ||
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}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ions.Logging.Abstractions.Tests/Thinktecture.Extensions.Logging.Abstractions.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters