serilog-sinks-http icon indicating copy to clipboard operation
serilog-sinks-http copied to clipboard

After NET 8 upgrade - FileNotFoundException (Serilog.Sinks.PeriodicBatching)

Open erikthysell opened this issue 1 year ago • 4 comments

Describe the bug

After upgrading my project to NET 8 (from NET 6) I get the following error: I have the same issue here but using Http sink: Errror:

[01/05/2024 08:32:32 > b80a7a: ERR ] Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Serilog.Sinks.PeriodicBatching, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10'. The system cannot find the file specified. [01/05/2024 08:32:32 > b80a7a: ERR ] File name: 'Serilog.Sinks.PeriodicBatching, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10' [01/05/2024 08:32:32 > b80a7a: ERR ] at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound) [01/05/2024 08:32:32 > b80a7a: ERR ] at System.Reflection.Assembly.Load(AssemblyName assemblyRef) [01/05/2024 08:32:32 > b80a7a: ERR ] at Serilog.Settings.Configuration.ConfigurationReader.LoadConfigurationAssemblies(IConfiguration section, AssemblyFinder assemblyFinder) [01/05/2024 08:32:32 > b80a7a: ERR ] at Serilog.Settings.Configuration.ConfigurationReader..ctor(IConfiguration configSection, AssemblyFinder assemblyFinder, ConfigurationReaderOptions readerOptions, IConfiguration configuration) [01/05/2024 08:32:32 > b80a7a: ERR ] at Serilog.ConfigurationLoggerConfigurationExtensions.GetConfigurationReader(IConfiguration configuration, ConfigurationReaderOptions readerOptions, DependencyContext dependencyContext) [01/05/2024 08:32:32 > b80a7a: ERR ] at Serilog.ConfigurationLoggerConfigurationExtensions.Configuration(LoggerSettingsConfiguration settingConfiguration, IConfiguration configuration, ConfigurationReaderOptions readerOptions) [01/05/2024 08:32:32 > b80a7a: ERR ] at MyAzureSolusion.MyService.Program.Main(String[] args) in D:\WorkLib\DkDep372\Default_Win2019\1\44\s\MyAzureSolusion.MyService\Program.cs:line 17

And line 17 in the Program.cs looks like this:

 Log.Logger = new LoggerConfiguration()
     .ReadFrom.Configuration(Configuration)
     .WriteTo.Http("https://myloghandeling/api/LogHub/MyService",null, httpClient: new CustomHttpClient())
     .Enrich.FromLogContext()
     .Destructure.ToMaximumDepth(3)
     .CreateLogger();

where the CustomHttpClient looks like this:

public class CustomHttpClient : IHttpClient
{
    private readonly HttpClient httpClient;

    public CustomHttpClient() => httpClient = new HttpClient();

    public void Configure(IConfiguration configuration) => httpClient.DefaultRequestHeaders.Add("MyToken", TokenContainer.MyToken);

    public Task<HttpResponseMessage> PostAsync(string requestUri, HttpContent content) => httpClient.PostAsync(requestUri, content);

    public void Dispose() => httpClient?.Dispose();

    public async Task<HttpResponseMessage> PostAsync(string requestUri, Stream contentStream)
    {
        using (var content = new StreamContent(contentStream))
        {
            content.Headers.Add("Content-Type", "application/json");
            return await httpClient.PostAsync(requestUri, content);
        }
    }
}

appsettings.json containes this:

"Serilog": {
  "MinimumLevel": {
    "Default": "Information",
    "Override": {
      "Microsoft": "Warning",
      "Microsoft.EntityFrameworkCore.Database.Command": "Warning",
      "System": "Warning"
    }
  },
  "WriteTo": [
    { "Name": "Console" }
  ]
},

MyService.csproj contains this:

 <PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
 <PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
 <PackageReference Include="Serilog.Sinks.Http" Version="8.0.0" />

Expected behavior Normal start...

Desktop (please complete the following information):

  • OS: Azure Webjob 64 bit

erikthysell avatar Jan 05 '24 09:01 erikthysell

Hi there and welcome to this repository!

A maintainer will be with you shortly, but first and foremost I would like to thank you for taking the time to report this issue. Quality is of the highest priority for us, and we would never release anything with known defects. We aim to do our best but unfortunately you are here because you encountered something we didn't expect. Lets see if we can figure out what went wrong and provide a remedy for it.

github-actions[bot] avatar Jan 05 '24 09:01 github-actions[bot]

The sample project serilog-sinks-http-sample-dotnet-core is also using net8.0, and it seems to run fine. Can you please verify?

FantasticFiasco avatar Jan 08 '24 20:01 FantasticFiasco

@FantasticFiasco I am not sure where the issue lies, it runs fine locally on my machine but not published to azure (sorry forgot to mention that before). So I guess it could be an azure thing....

erikthysell avatar Jan 09 '24 16:01 erikthysell

Please let me know if you find this to be an issue for this sink. If not please, close the issue, and if you have the time please tell me what the reason was as I'm interested.

FantasticFiasco avatar Jan 15 '24 06:01 FantasticFiasco