serilog-mssql / serilog-sinks-mssqlserver

A Serilog sink that writes events to Microsoft SQL Server and Azure SQL
Apache License 2.0
283 stars 148 forks source link

CultureNotFoundException: en-us is an invalid culture identifier #507

Closed talos79 closed 2 months ago

talos79 commented 11 months ago

Please clearly describe what the SQL Sink is doing incorrectly:

.Net 8.0 API build correctly but when trying to debug in visual studio (F5) this is the exception:

CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
en-us is an invalid culture identifier.

Please clearly describe the expected behavior:

Have logs saved in database table

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

Target framework and operating system: .NET 8 OS: Windows

Provide a simple reproduction of your Serilog configuration code:

appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "Serilog": {
    "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.MSSqlServer", "Serilog.Sinks.File" ],
    "MinimumLevel": "Information",
    "WriteTo": [
      {
        "Name": "Console"
      },
      {
        "Name": "File",
        "Args": {
          "path": ".\\Logs\\LogEvents-.txt",
          "rollingInterval": "Day",
          "rollOnFileSizeLimit": true
        }
        },
        {
          "Name": "MSSqlServer",
          "Args": {
            "connectionString": "myConnectionString",
            "sinkOptionsSection": {
              "tableName": "LogEvents",
              "batchPostingLimit": 100,
              "period": "0.00:00:10"
            },
            "restrictedToMinimumLevel": "Warning"
          }
        }
    ]
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "cnSql": "myConnectionString"
  }
}

Provide a simple reproduction of your application code: Program.cs


using Serilog;

var builder = WebApplication.CreateBuilder(args);

//Add support to logging with SERILOG builder.Host.UseSerilog((context, configuration) => configuration.ReadFrom.Configuration(context.Configuration));

builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen();

var app = builder.Build();

app.UseHttpsRedirection();

//Add support to logging request with SERILOG app.UseSerilogRequestLogging();

app.UseAuthorization();

app.MapControllers();

app.Run();

sonzo commented 10 months ago

If the project used is generated via Visual Studio, then look in your csproj for this

<InvariantGlobalization>true</InvariantGlobalization>

and remove it.

https://github.com/dotnet/aspnetcore/issues/52319

nitewulf commented 6 months ago

I don't have any issues running locally. But I am getting that same error trying to run my API using this sink in docker. My project file does not have that property.

ckadluba commented 6 months ago

@nitewulf I could not reproduce the described problem. Do you have a full stack trace and perhaps a minimal but complete sample project for us to reproduce the exception?

ckadluba commented 2 months ago

Closed due do inactivity and because I could not reproduce the issue.