skip to Main Content

I am trying to include serilog in my Azure function App project (.net 6), My Startup.cs

public override void Configure(IFunctionsHostBuilder builder)
 {
        Log.Logger = new LoggerConfiguration()
        .WriteTo.Console()
        .WriteTo.AzureAnalytics(workspaceId: "xxxxxxxxxxxxxxxxxxxxxxx",
        authenticationId: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
        .CreateLogger();

        builder.Services.AddLogging(lb => lb.AddSerilog(Log.Logger,true));

        ConfigureServices(builder.Services);
    }

    private void ConfigureServices(IServiceCollection services)
    {
        services.RegisterApplicationServices();

    }

My csproj

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <DockerFastModeProjectMountDirectory>/home/site/wwwroot</DockerFastModeProjectMountDirectory>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.18.1" />
    <PackageReference Include="Serilog" Version="3.0.1" />
    <PackageReference Include="Serilog.Extensions.Logging" Version="7.0.0" />
    <PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="4.0.0" />
    <PackageReference Include="Serilog.Sinks.AzureAnalytics" Version="5.0.0" />
    <PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
</ItemGroup>
<ItemGroup>
    <ProjectReference Include="..xxxx.Applicationxxxxx.Application.csproj" />
</ItemGroup>
<ItemGroup>
    <None Update="host.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
</ItemGroup>

ref

Everything seems to be in place but I am getting this error when running the app locally

A host error has occurred during startup operation ‘677c62b7-bf08-4306-812c-e7ea5fbd5678’.
[2023-08-01T15:21:25.432Z] Microsoft.Azure.WebJobs.Script: Error configuring services in an external startup class. ConcurICS.FunctionApp: Could not load file or assembly ‘Microsoft.Extensions.Logging, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60’. The system cannot find the file specified.

2

Answers


  1. This may sound stupit, but try this in the Package Manager console:

    Update-Package -reinstall. 
    

    It solved way too many package problems for me that should’t be a problem.

    If that didn’t help. Can you provide what you have already tried?

    Login or Signup to reply.
  2. Try downgrading Serilog.Extensions.Logging to 3.1.0 version (in my sample set up I was using Serilog.Extensions.Hosting with 5.0.1 version which depends on it)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search