Using Serilog for Blazor Server solution -> "IHostBuilder does not contain a definition for 'UseSerilog'

Viewed 457

I am trying to implement Serilog for my Blazorserver project.

First and foremost, i follow the instructions as described in the link https://www.c-sharpcorner.com/article/log-data-into-file-using-serilog-framework-in-blazor-server-app/.

In this instruction the following lines appear in the second code block:

Host.CreateDefaultBuilder(args)  
.UseSerilog()  
    .ConfigureWebHostDefaults(webBuilder =>  
    {  
        webBuilder.UseStartup<Startup>();  
    }); 

Where the line .Useserilog() is newly added. The precompiler now throws the following error message:

"IHostBuilder does not contain a definition for 'UseSerilog'

I have added using Serilog and using Serilog.Events in the Program.cs file (all "usings" are listed here):

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Serilog;
using Serilog.Events;

Does anyone have any idea what could be causing the problem? Thanks!

1 Answers

UseSerilog is an extension method in the Serilog.Extensions.Hosting namespace so you will need to import that:

using Serilog.Extensions.Hosting;

You may also need to add the Serilog.Extensions.Hosting Nuget package.

Related