I have below configuration for serilog now which I want to move as a Extension method,
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((ctx, lc) => _ = builder.Environment.IsDevelopment()
? lc.WriteTo.Console()
: lc.WriteTo.AzureBlobStorage());
When I tried to write below in a separate class library, I am not able to find WebApplicationBuilder
reference,
public static void ConfigureSerilog(this WebApplicationBuilder builder)
{
}
The type or namespace name 'WebApplicationBuilder' could not be found (are you missing a using directive or an assembly reference?)
CodePudding user response:
Your regular class library targets Microsoft.NET.Sdk
.In order to use asp.net core in your class library
Add
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
to your class library .csproj and then add
using Microsoft.AspNetCore.Builder;
which contains WebApplicationBuilder