diff --git a/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs b/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs index 9a82609..3aa7fb1 100644 --- a/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs +++ b/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLogger.cs @@ -103,12 +103,12 @@ LogEvent PrepareWrite(LogEventLevel level, EventId eventId, TState state { messageTemplate = value; } - else if (property.Key.StartsWith("@")) + else if (property.Key.StartsWith('@')) { if (_logger.BindProperty(GetKeyWithoutFirstSymbol(DestructureDictionary, property.Key), property.Value, true, out var destructured)) properties.Add(destructured); } - else if (property.Key.StartsWith("$")) + else if (property.Key.StartsWith('$')) { if (_logger.BindProperty(GetKeyWithoutFirstSymbol(StringifyDictionary, property.Key), property.Value?.ToString(), true, out var stringified)) properties.Add(stringified); diff --git a/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerScope.cs b/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerScope.cs index baefd6d..ca16691 100644 --- a/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerScope.cs +++ b/src/Serilog.Extensions.Logging/Extensions/Logging/SerilogLoggerScope.cs @@ -55,12 +55,12 @@ void AddProperty(string key, object? value) { var destructureObject = false; - if (key.StartsWith("@")) + if (key.StartsWith('@')) { key = SerilogLogger.GetKeyWithoutFirstSymbol(SerilogLogger.DestructureDictionary, key); destructureObject = true; } - else if (key.StartsWith("$")) + else if (key.StartsWith('$')) { key = SerilogLogger.GetKeyWithoutFirstSymbol(SerilogLogger.StringifyDictionary, key); value = value?.ToString(); diff --git a/src/Serilog.Extensions.Logging/Extensions/StringExtensions.cs b/src/Serilog.Extensions.Logging/Extensions/StringExtensions.cs new file mode 100644 index 0000000..0e072b9 --- /dev/null +++ b/src/Serilog.Extensions.Logging/Extensions/StringExtensions.cs @@ -0,0 +1,14 @@ +using System.Runtime.CompilerServices; + +namespace Serilog.Extensions; + +#if !NET6_0_OR_GREATER && !NETSTANDARD2_1_OR_GREATER +static class StringExtensions +{ + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool StartsWith(this string str, char value) + { + return str.Length > 0 && str[0] == value; + } +} +#endif