8
8
using Serilog . Core ;
9
9
using Serilog . Events ;
10
10
11
- namespace Serilog . Sinks . Exceptionless {
11
+ namespace Serilog . Sinks . Exceptionless
12
+ {
12
13
/// <summary>
13
14
/// Exceptionless Sink
14
15
/// </summary>
15
- public class ExceptionlessSink : ILogEventSink , IDisposable {
16
+ public class ExceptionlessSink : ILogEventSink , IDisposable
17
+ {
16
18
private readonly string [ ] _defaultTags ;
17
19
private readonly Func < EventBuilder , EventBuilder > _additionalOperation ;
18
20
private readonly bool _includeProperties ;
@@ -47,11 +49,13 @@ public ExceptionlessSink(
47
49
Func < EventBuilder , EventBuilder > additionalOperation = null ,
48
50
bool includeProperties = true ,
49
51
LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
50
- ) {
52
+ )
53
+ {
51
54
if ( apiKey == null )
52
55
throw new ArgumentNullException ( nameof ( apiKey ) ) ;
53
56
54
- _client = new ExceptionlessClient ( config => {
57
+ _client = new ExceptionlessClient ( config =>
58
+ {
55
59
if ( ! String . IsNullOrEmpty ( apiKey ) && apiKey != "API_KEY_HERE" )
56
60
config . ApiKey = apiKey ;
57
61
@@ -84,23 +88,26 @@ public ExceptionlessSink(
84
88
/// The minimum log event level required in order to write an event to the sink.
85
89
/// </param>
86
90
public ExceptionlessSink (
87
- Func < EventBuilder , EventBuilder > additionalOperation = null ,
88
- bool includeProperties = true ,
91
+ Func < EventBuilder , EventBuilder > additionalOperation = null ,
92
+ bool includeProperties = true ,
89
93
ExceptionlessClient client = null ,
90
94
LogEventLevel restrictedToMinimumLevel = LevelAlias . Minimum
91
- ) {
95
+ )
96
+ {
92
97
_additionalOperation = additionalOperation ;
93
98
_includeProperties = includeProperties ;
94
99
_client = client ?? ExceptionlessClient . Default ;
95
100
96
- if ( _client . Configuration . Resolver . HasDefaultRegistration < IExceptionlessLog , NullExceptionlessLog > ( ) ) {
101
+ if ( _client . Configuration . Resolver . HasDefaultRegistration < IExceptionlessLog , NullExceptionlessLog > ( ) )
102
+ {
97
103
_client . Configuration . UseLogger ( new SelfLogLogger ( ) ) ;
98
104
}
99
105
100
106
_client . Configuration . SetDefaultMinLogLevel ( restrictedToMinimumLevel . GetLevel ( ) ) ;
101
107
}
102
108
103
- public void Emit ( LogEvent logEvent ) {
109
+ public void Emit ( LogEvent logEvent )
110
+ {
104
111
if ( logEvent == null || ! _client . Configuration . IsValid )
105
112
return ;
106
113
@@ -110,7 +117,8 @@ public void Emit(LogEvent logEvent) {
110
117
111
118
var builder = _client . CreateFromLogEvent ( logEvent ) . AddTags ( _defaultTags ) ;
112
119
113
- if ( _includeProperties ) {
120
+ if ( _includeProperties )
121
+ {
114
122
foreach ( var prop in logEvent . Properties )
115
123
{
116
124
switch ( prop . Key )
@@ -142,7 +150,7 @@ public void Emit(LogEvent logEvent) {
142
150
case "Tags" :
143
151
builder . AddTags ( prop . Value . GetTags ( ) ) ;
144
152
break ;
145
- default :
153
+ default :
146
154
builder . SetProperty ( prop . Key , prop . Value . FlattenProperties ( ) ) ;
147
155
break ;
148
156
}
@@ -153,7 +161,8 @@ public void Emit(LogEvent logEvent) {
153
161
builder . Submit ( ) ;
154
162
}
155
163
156
- void IDisposable . Dispose ( ) {
164
+ void IDisposable . Dispose ( )
165
+ {
157
166
_client ? . ProcessQueueAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
158
167
}
159
168
}
0 commit comments