File tree Expand file tree Collapse file tree 1 file changed +25
-4
lines changed
examples/Thinktecture.Extensions.Logging.Abstractions.Example Expand file tree Collapse file tree 1 file changed +25
-4
lines changed Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . Linq ;
2
3
using Microsoft . Extensions . Logging ;
3
4
using Serilog ;
5
+ using Serilog . Core ;
6
+ using Serilog . Events ;
4
7
5
8
namespace Thinktecture . Extensions . Logging . Abstractions . Example
6
9
{
@@ -9,11 +12,12 @@ class Program
9
12
static void Main ( string [ ] args )
10
13
{
11
14
var serilog = new LoggerConfiguration ( )
12
- . WriteTo . Console ( )
13
- . CreateLogger ( ) ;
15
+ . WriteTo . Console ( )
16
+ . WriteTo . Sink ( new MySink ( ) )
17
+ . CreateLogger ( ) ;
14
18
var logger = new LoggerFactory ( )
15
- . AddSerilog ( serilog )
16
- . CreateLogger < Program > ( ) ;
19
+ . AddSerilog ( serilog )
20
+ . CreateLogger < Program > ( ) ;
17
21
18
22
var a = "text" ;
19
23
var b = 42 ;
@@ -24,4 +28,21 @@ static void Main(string[] args)
24
28
Console . ReadLine ( ) ;
25
29
}
26
30
}
31
+
32
+ internal class MySink : ILogEventSink
33
+ {
34
+ public void Emit ( LogEvent logEvent )
35
+ {
36
+ Console . WriteLine ( ) ;
37
+ Console . WriteLine ( $ "Template: { logEvent . MessageTemplate . Text } ") ;
38
+ Console . WriteLine ( "Properties:" ) ;
39
+
40
+ foreach ( var kvp in logEvent . Properties )
41
+ {
42
+ // Issue: formattable string does not capture the names of the placeholders
43
+ // https://github.com/dotnet/roslyn/issues/142
44
+ Console . WriteLine ( $ "\t { kvp . Key } = { kvp . Value } ") ;
45
+ }
46
+ }
47
+ }
27
48
}
You can’t perform that action at this time.
0 commit comments