serilog / serilog-aspnetcore

Serilog integration for ASP.NET Core
Apache License 2.0
1.29k stars 203 forks source link

Issue with using UseSerilog in dotnet7 #342

Closed Veeraraghavans closed 1 year ago

Veeraraghavans commented 1 year ago

Hi Team,

I am trying to use Serilog for capturing logs for my Opentelemetry. When I am using Web App console example into my code I am getting following error

error CS1929: 'ConfigureHostBuilder' does not contain a definition for 'UseSerilog' and the best extension method overload 'SerilogWebHostBuilderExtensions.UseSerilog(IWebHostBuilder, ILogger?, bool, LoggerProviderCollection?)' requires a receiver of type 'IWebHostBuilder'

Background of the work,

I am using dotnet7 framework and using Bazel to build the packages. The Aspcore and .NET core are at version 7. The Serilog version is 3.0.1 and Serilog.AspNetCore is 7.0.0.

Code which getting error is

 Log.Information("Starting web application");
 var builder = WebApplication.CreateBuilder(args);
 builder.Host.UseSerilog(); // <-- Add this line //Error here

I would like to know is their any dependency issue or I am missing something? It would be helpful if you can hint me some directions what all could lead to such a error. Thanks again

sungam3r commented 1 year ago

Try builder.Services.UseSerilog();

Veeraraghavans commented 1 year ago

It didnt work I get error as below:

'IServiceCollection' does not contain a definition for 'UseSerilog' and the best extension method overload 'SerilogWebHostBuilderExtensions.UseSerilog(IWebHostBuilder, ILogger?, bool, LoggerProviderCollection?)' requires a receiver of type 'IWebHostBuilder'

Veeraraghavans commented 1 year ago

Fixed this issue by importing serilog.extensions.hosting