Skip to content

Commit 764ae5a

Browse files
Only add thread name if not null
Test to only add the porperty iff Thread.Name is not null.
1 parent cdce12d commit 764ae5a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Serilog.Enrichers.Thread/Enrichers/ThreadNameEnricher.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ public class ThreadNameEnricher : ILogEventEnricher
3838
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
3939
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
4040
{
41-
logEvent.AddPropertyIfAbsent(new LogEventProperty(ThreadNamePropertyName, new ScalarValue(Thread.CurrentThread.Name)));
41+
var threadName = Thread.CurrentThread.Name;
42+
if (threadName != null)
43+
{
44+
logEvent.AddPropertyIfAbsent(new LogEventProperty(ThreadNamePropertyName, new ScalarValue(Thread.CurrentThread.Name)));
45+
}
4246
}
4347
}
4448
#endif

0 commit comments

Comments
 (0)