apm-agent-dotnet: Using Serilog with Elastic APM causes NullReferenceException
Describe the bug When using Serilog and Elastic APM together in Asp.Net COre, a NullReferenceException is thrown on start-up.
Versions: netcoreapp 2.1 Elastic.Apm.NetCoreAll 1.1.1 Serilog.AspnetCore 3.0.0
To Reproduce Steps to reproduce the behavior:
- Clone this repo: https://github.com/scotmeiste/elastic-apm-serilog-error
- in appsettings.json, replace ServerUrls and SecretToken with your instance of Elastic APM
- Run Web Api project
- See error in debug output (Debug Console tab in VS Code)
Elastic APM .NET Agent: [CRITICAL] Exception thrown by logging implementation. Log message: `The agent was started without a service name. The automatically discovered service name is {ServiceName}'. args.Length: 1. Current thread: managed ID: 1
Elastic APM .NET Agent: +-> Exception (exception): System.NullReferenceException: Object reference not set to an instance of an object.
Elastic APM .NET Agent: at Serilog.Extensions.Logging.SerilogLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
at Elastic.Apm.AspNetCore.AspNetCoreLogger.Log[TState](LogLevel level, TState state, Exception e, Func`3 formatter)
at Elastic.Apm.Logging.LoggingExtensions.DoLog(IApmLogger logger, LogLevel level, String message, Exception e, Object[] args)e: <null>
Expected behavior Either no error, or a more helpful description of what went wrong.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (10 by maintainers)
@scotm-gxg: The patch with the fix is out: https://github.com/elastic/apm-agent-dotnet/releases/tag/1.1.2 - so
1.1.2should be ok with Serilog. The packages are also updated on nuget.org.Awesome!
Regarding release: we already have 2 fairly important fixes on master. We don’t make promises on release dates, but I think having those 2 fixes out there would be important, so I’m thinking about a patch release very soon.
Alright, looks like its working now!
Thanks for posting that fork/PR. it helped a ton. And thanks for the assistance!
Any idea when this will get rolled into a release? No rush or anything, just want to make sure I update the fix on my main project.
@scotm-gxg thanks for the update. I’ll fork your repo and try myself.
Glad that test project helped!
I tried building your PR locally, but I got the error again. its near the end of my day here, so I will check it again in the morning to see if I got the right branch and built it correctly and all that.
Thanks again for your help!
As it seems, all our structured logs with serilog throw an exception.
Already something like this ends up with a
NullReferenceException: