question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using Serilog with Elastic APM causes NullReferenceException

See original GitHub issue

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:

  1. Clone this repo: https://github.com/scotmeiste/elastic-apm-serilog-error
  2. in appsettings.json, replace ServerUrls and SecretToken with your instance of Elastic APM
  3. Run Web Api project
  4. 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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
gregkalaposcommented, Oct 11, 2019

@scotm-gxg: The patch with the fix is out: https://github.com/elastic/apm-agent-dotnet/releases/tag/1.1.2 - so 1.1.2 should be ok with Serilog. The packages are also updated on nuget.org.

1reaction
gregkalaposcommented, Oct 10, 2019

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.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Serilog with Elastic APM causes ...
Describe the bug When using Serilog and Elastic APM together in Asp.Net COre, a NullReferenceException is thrown on start-up.
Read more >
Serilog | APM .NET Agent Reference [1.x]
We offer a Serilog Enricher that adds the trace id to every log line that is created during an active trace. The enricher...
Read more >
Developers - Using Serilog with Elastic APM causes ...
Using Serilog with Elastic APM causes NullReferenceException.
Read more >
Serilog does not send log to Elasticsearch asp.net core
I'm using Serilog and Elasticearch For my asp.net core app but when I open Kibana ... TypeName = null, AutoRegisterTemplate = true, ...
Read more >
Logging With ElasticSearch, Kibana, Serilog Using ASP. ...
In this article, I'll show you how to set up and run your application using ElasticSearch, Kibana and Serilog.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found