BlazorExtensions / Logging

Microsoft Extension Logging implementation for Blazor
MIT License
216 stars 31 forks source link

Unhandled Exception during log write #55

Closed ordinaryorange closed 3 years ago

ordinaryorange commented 4 years ago

Using Blazor Webassembly project. I have Logging configured and working for simple logging scenarios, but have discovered that the logging service will throw an exception when passed more complex objects.

For example this call Logger.LogDebug(typeof(DateTime).Assembly)

throws this in the console

image

Looks to be an issue with the JSON serialization.

chucker commented 4 years ago

Hmm. Does Console.WriteLine(typeof(DateTime).Assembly) work?

ordinaryorange commented 4 years ago

Yep works as expected. Console.WriteLine just effectively calls the .ToString() on the object. So it is not doing any deep property inspection like the Logger.

attilah commented 3 years ago

This is not a logger concern IMHO as this limitation comes from the WebAssembly support to serialize Assembly type, which fails using the default JSON serializer. If you need to serialize by default unsupported objects, then use the override for the log method that's accepting a Func<TState, Exception, string> formatter, so you can create message that is being sent to the browser or the FormattedLogObject instance as needed. In the next release the FormattedLogObject type will be public for this reason.