error CS1929: 'ConfigureHostBuilder' does not contain a definition for 'UseSerilog'

Veeraraghavan SEKAR 0 Reputation points

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

Microsoft Technologies based on the .NET software framework.
3,173 questions
A set of technologies in the .NET Framework for building web applications and XML web services.
4,013 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce ( 52,576 Reputation points

    you add to the Logging, not host. you also may want to clear other logger:

    // optional: remove default logging providers
    // Serilog configuration		
    var logger = new LoggerConfiguration()
    // Register Serilog