Andrey Klysheiko
Andrey Klysheiko

Reputation: 1

Serilog logging to Azure eventhub stopped working after moving project to .Net Core 5

I have a .Net Core 3.1 project that uses Serilog and posts messages to Azure Eventhub. The problems started when we moved it to .Net 5.

Here's how it's configured in Startup.cs in ConfigureServices we have section

var eventHubConfig = Configuration.GetSection("Logging").GetSection("eventHub");
            string eventHubConnection = eventHubConfig.GetValue<string>("connectionString");
            Log.Logger = new LoggerConfiguration()
                .WriteTo.AzureEventHub(new JsonFormatter(),
                    eventHubConnection.Replace(@"\", ""),
                    eventHubConfig.GetValue<string>("entityName"))
                .CreateLogger();

in Configure method we have: loggerFactory.AddSerilog(); and in Program.cs

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                 .UseSerilog()
                 .UseStartup<Startup>();

Very simple and it's working for .Net Core 3.1, but once I change the target framework for the project to .Net 5 it stops working.

Any thoughts? Has anyone seen the same issue?

Upvotes: 0

Views: 544

Answers (1)

Kristoffer Vidmo
Kristoffer Vidmo

Reputation: 11

Serilog uses an old version of Microsoft.Azure.EventHubs internally

I had the same issue and bumping to 4.3.2 solved the problem

Since then Microsoft.Azure.EventHubs have been deprecated and we have moved to Serilog 6 and Azure.Messaging.EventHubs

Upvotes: 1

Related Questions