Cysharp / ZLogger

Zero Allocation Text/Structured Logger for .NET with StringInterpolation and Source Generator, built on top of a Microsoft.Extensions.Logging.
MIT License
1.16k stars 81 forks source link

FormatException is thrown if the log message string contains "{". #11

Closed mxProject closed 4 years ago

mxProject commented 4 years ago

Hello @neuecc .

FormatException is thrown if the log message string contains "{".

Configure the console logger by calling the AddZLoggerConsole method.

await MagicOnionHost.CreateDefaultBuilder() .UseMagicOnion(options, new ServerPort("localhost", port, credentials)) .ConfigureLogging(logging => { logging.ClearProviders(); logging.AddZLoggerConsole(options => { options.EnableStructuredLogging = false; } ); } ) .RunConsoleAsync().ConfigureAwait(false);

Outputs a string containing "{" to the logger.

logger.ZLogInformation("{abc=1}");

FormatException is thrown.

System.FormatException: Input string was not in a correct format. at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type) at Cysharp.Text.FormatParser.Parse(ReadOnlySpan1 format) at Cysharp.Text.ZString.Utf8Format[T1](IBufferWriter1 bufferWriter, String format, T1 arg1) at ZLogger.Entries.FormatLogEntry2.FormatUtf8(IBufferWriter1 writer, ZLoggerOptions options, Utf8JsonWriter jsonWriter) at ZLogger.AsyncStreamLineMessageWriter.WriteLoop()

neuecc commented 4 years ago

Thank you for reporting. Currently Log(string msg) redirected to Log(string format, object null), which is causing an error. I'll fix soon.

neuecc commented 4 years ago

Now I've releade 1.2.1 it includes this fix.

mxProject commented 4 years ago

Thanks @neuecc