serilog-sinks-mssqlserver: PublishSingleFile fails at runtime

Please clearly describe what the SQL Sink is doing incorrectly:

When publishing a dotnet 5 project with PublishSingleFile=true and basic setup it will fail at runtime with

Unhandled exception. System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.IO.FileNotFoundException: The system cannot find the file specified. (0x80070002) at System.Reflection.RuntimeModule.GetFullyQualifiedName() at System.Reflection.RuntimeModule.get_Name() at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig) at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig) at System.Configuration.ClientConfigurationHost.get_ConfigPaths() at System.Configuration.ClientConfigurationHost.GetStreamName(String configPath) at System.Configuration.ClientConfigurationHost.get_IsAppConfigHttp() at System.Configuration.Internal.DelegatingConfigHost.get_IsAppConfigHttp() at System.Configuration.ClientConfigurationSystem..ctor() at System.Configuration.ConfigurationManager.EnsureConfigurationSystem() --- End of inner exception stack trace --- at System.Configuration.ConfigurationManager.EnsureConfigurationSystem() at System.Configuration.ConfigurationManager.PrepareConfigSystem() at System.Configuration.ConfigurationManager.GetSection(String sectionName) at Serilog.Sinks.MSSqlServer.ApplySystemConfiguration.GetSinkConfigurationSection(String configurationSectionName)

Please clearly describe the expected behavior:

No error. Removing the sink fixes the problem.

List the names and versions of all Serilog packages used in the project:

  • “Serilog” Version=“2.10.0”
  • “Serilog.Extensions.Hosting” Version=“3.1.0”
  • “Serilog.Sinks.Console” Version=“3.1.1”
  • “Serilog.Sinks.MSSqlServer” Version=“5.6.0”

Target framework and operating system:

[ ] .NET 5.x OS: Windows

Provide a simple reproduction of your Serilog configuration code:

            .UseSerilog((hostingContext, services, loggerConfiguration) => loggerConfiguration
                .MinimumLevel.Information()
                .WriteTo.Console()
                .WriteTo.MSSqlServer("DefaultConnection", new MSSqlServerSinkOptions
                {
                    TableName = "Logs",
                    SchemaName = "EventLogging",
                    AutoCreateSqlTable = true,
                    BatchPostingLimit = 1000,
                    BatchPeriod = new TimeSpan(0, 0, 30)
                })
                .Enrich.FromLogContext()

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 19 (9 by maintainers)

Most upvoted comments

Hi,

I’ve managed to reproduce the issue as well. First I thought the only requirement is that you set PublishSingleFile flag to true, but you need to set it to self contained too.