File tree Expand file tree Collapse file tree 3 files changed +61
-2
lines changed
src/Serilog.Enrichers.Thread Expand file tree Collapse file tree 3 files changed +61
-2
lines changed Original file line number Diff line number Diff line change 1
- // Copyright 2013-2015 Serilog Contributors
1
+ // Copyright 2013-2019 Serilog Contributors
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
Original file line number Diff line number Diff line change
1
+ // Copyright 2013-2019 Serilog Contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+
16
+ using System . Threading ;
17
+ using Serilog . Core ;
18
+ using Serilog . Events ;
19
+
20
+ namespace Serilog . Enrichers {
21
+ #if NET45 || NETSTANDARD2_0
22
+ /// <summary>
23
+ /// Enriches log events with a ThreadName property containing the
24
+ /// </summary>
25
+ public class ThreadNameEnricher : ILogEventEnricher
26
+ {
27
+
28
+ /// <summary>
29
+ /// The property name added to enriched log events.
30
+ /// </summary>
31
+ public const string ThreadNamePropertyName = "ThreadName" ;
32
+
33
+
34
+ /// <summary>
35
+ /// Enrich the log event.
36
+ /// </summary>
37
+ /// <param name="logEvent">The log event to enrich.</param>
38
+ /// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
39
+ public void Enrich ( LogEvent logEvent , ILogEventPropertyFactory propertyFactory )
40
+ {
41
+ logEvent . AddPropertyIfAbsent ( new LogEventProperty ( ThreadNamePropertyName , new ScalarValue ( Thread . CurrentThread . Name ) ) ) ;
42
+ }
43
+ }
44
+ #endif
45
+ }
Original file line number Diff line number Diff line change 1
- // Copyright 2013-2016 Serilog Contributors
1
+ // Copyright 2013-2019 Serilog Contributors
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
@@ -38,5 +38,19 @@ public static LoggerConfiguration WithThreadId(
38
38
if ( enrichmentConfiguration == null ) throw new ArgumentNullException ( nameof ( enrichmentConfiguration ) ) ;
39
39
return enrichmentConfiguration . With < ThreadIdEnricher > ( ) ;
40
40
}
41
+
42
+ #if NET45 || NETSTANDARD2_0
43
+ /// <summary>
44
+ /// Enrich log events with a ThreadName property containing the <see cref="Thread.CurrentThread"/> <see cref="Thread.Name"/>.
45
+ /// </summary>
46
+ /// <param name="enrichmentConfiguration"></param>
47
+ /// <returns></returns>
48
+ public static LoggerConfiguration WithThreadName (
49
+ this LoggerEnrichmentConfiguration enrichmentConfiguration )
50
+ {
51
+ if ( enrichmentConfiguration == null ) throw new ArgumentNullException ( nameof ( enrichmentConfiguration ) ) ;
52
+ return enrichmentConfiguration . With < ThreadNameEnricher > ( ) ;
53
+ }
54
+ #endif
41
55
}
42
56
}
You can’t perform that action at this time.
0 commit comments