NLog logging to Graylog: unexpected Newtonsoft.Json.JsonSerializationException
I was trying to add Graylog support to a project. I added the latest NLog.Web.AspNetCore
and NLog.Web.AspNetCore.Targets.Gelf
packages, and set up the correct NLog.config file. I got the following exception message in the /c/temp/nloginternallog_bankblanceapi.txt
Error GelfTarget(Name=graylog): Exception in Write Exception: Newtonsoft.Json.JsonSerializationException: Self referencing loop detected for property 'Module' with type 'System.Reflection.RuntimeModule'. Pat
h 'Metadata[8].MethodInfo.Module.Assembly.EntryPoint'.
I googled quite a while but didn't get a workaround. Eventually, I got the following solution:
Downgrade the NLog.Web.AspNetCore package to version 4.15.0, and that exception is gone! I didn't try other versions, so I don't know exactly which version introduced this issue.