Skip to content

Instantly share code, notes, and snippets.

@niemyjski
Created March 7, 2024 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niemyjski/465e55a8d019a9260ae6e52d952260d2 to your computer and use it in GitHub Desktop.
Save niemyjski/465e55a8d019a9260ae6e52d952260d2 to your computer and use it in GitHub Desktop.
.NET always Parsing log formats
[Fact]
public void TestLogLevel()
{
Log.MinimumLevel = LogLevel.Information;
var logger = Log.CreateLogger("TestLogLevel");
logger.LogTrace("({BadBracket}}", Boolean.TrueString);
}
System.FormatException
Input string was not in a correct format. Failure to parse near offset 10. Format item ends prematurely.
at System.Text.CompositeFormat.Parse(String format)
at Microsoft.Extensions.Logging.LogValuesFormatter..ctor(String format)
at Microsoft.Extensions.Logging.FormattedLogValues.<>c.<.ctor>b__9_0(String f)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Extensions.Logging.FormattedLogValues..ctor(String format, Object[] values)
at Microsoft.Extensions.Logging.LoggerExtensions.Log(ILogger logger, LogLevel logLevel, EventId eventId, Exception exception, String message, Object[] args)
at Microsoft.Extensions.Logging.LoggerExtensions.LogTrace(ILogger logger, String message, Object[] args)
at Tests.LoggingTests.TestLogLevel() in /Users/blakeniemyjski/test/Tests/LoggingTests.cs:line 24
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment