diff --git a/Mindscape.Raygun4Net.Extensions.Logging/RaygunLogger.cs b/Mindscape.Raygun4Net.Extensions.Logging/RaygunLogger.cs index 063ccee5..1e0f5d23 100644 --- a/Mindscape.Raygun4Net.Extensions.Logging/RaygunLogger.cs +++ b/Mindscape.Raygun4Net.Extensions.Logging/RaygunLogger.cs @@ -11,7 +11,7 @@ public class RaygunLogger : ILogger private readonly string _category; private readonly RaygunClientBase _client; private readonly RaygunLoggerSettings _settings; - private readonly AsyncLocal> _scopeData = new(); + private readonly AsyncLocal> _scopeData = new(); /// /// Initializes a new instance of the RaygunLogger. @@ -67,7 +67,7 @@ public void Log(LogLevel logLevel, EventId eventId, TState state, Except { foreach (var item in _scopeData.Value) { - customData[$"Scope{item.Key}"] = item.Value.ToString() ?? string.Empty; + customData[$"Scope{item.Key}"] = item.Value?.ToString() ?? string.Empty; } } @@ -134,14 +134,14 @@ public IDisposable BeginScope(TState state) var scopeData = _scopeData.Value; if (scopeData == null) { - scopeData = new Dictionary(); + scopeData = new Dictionary(); _scopeData.Value = scopeData; } // Handle different types of state switch (state) { - case IEnumerable> properties: + case IEnumerable> properties: foreach (var prop in properties) { scopeData[$"[{scopeData.Count}].{prop.Key}"] = prop.Value; @@ -157,9 +157,9 @@ public IDisposable BeginScope(TState state) private class RaygunLoggerScope : IDisposable { - private readonly AsyncLocal> _scopeData; + private readonly AsyncLocal> _scopeData; - public RaygunLoggerScope(AsyncLocal> scopeData) + public RaygunLoggerScope(AsyncLocal> scopeData) { _scopeData = scopeData; } @@ -169,4 +169,4 @@ public void Dispose() _scopeData.Value?.Clear(); } } -} \ No newline at end of file +}