Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
talos79 opened this issue Dec 27, 2023 · 4 comments
Closed

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

talos79 opened this issue Dec 27, 2023 · 4 comments

Comments

@talos79
Copy link

talos79 commented Dec 27, 2023

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:

  • Serilog.AspNetCore: 8.0.0
  • Serilog.Settings.Configuration: 8.0.0
  • Serilog.Sinks.MSSqlServer: 6.5.0
  • Serilog.Sinks.Console: 5.0.1
  • Serilog.Sinks.File: 5.0.0

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
Copy link

sonzo commented Jan 26, 2024

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

<InvariantGlobalization>true</InvariantGlobalization>

and remove it.

dotnet/aspnetcore#52319

@nitewulf
Copy link

nitewulf commented May 1, 2024

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
Copy link
Member

@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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants