I have a blazor web assembly hosted solution which uses Serilog to write to the SQL DB.
In the client I have to following in the Program Main
//Serilog
var levelSwitch = new LoggingLevelSwitch();
Serilog.Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(levelSwitch)
.Enrich.WithProperty("InstanceId", Guid.NewGuid())
.Enrich.FromLogContext()
.WriteTo.BrowserHttp(controlLevelSwitch: levelSwitch)
.CreateLogger();
Serilog.Log.ForContext<Program>().Information("Client has started");
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.Services.AddLogging(logging =>
{
logging.ClearProviders();
logging.AddSerilog(dispose: true);
});
In the server Startup i have the following in the Configure
app.UseSerilogIngestion();
app.UseSerilogRequestLogging();
Here is my appsettings.json
"Serilog": {
"Using": [ "Serilog.Sinks.MSSqlServer" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.Authorization.DefaultAuthorizationService": "Warning",
"Microsoft.EntityFrameworkCore": "Warning",
"System": "Warning",
"System.Net.Http*": "Warning",
"IdentityServer4": "Warning",
"Serilog.AspNetCore": "Warning"
}
},
"WriteTo": [
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "DefaultConnection",
"sinkOptionsSection": {
"tableName": "Logs"
},
"columnOptionsSection": {
"additionalColumns": [
{
"ColumnName": "InstanceId"
},
{
"ColumnName": "Origin"
},
{
"ColumnName": "SourceContext"
},
{
"ColumnName": "UserId"
},
{
"ColumnName": "Username"
}
],
"excludeAdditionalProperties": true
}
}
}
]
},
When I go to deploy this to Azure the logging stops working. Mainly because the Args "connectionString":"DefaultConnection" is never being replaced with the connection string at deployment.
I have the following for the Service Dependencies which changes the main ConnectionString in the appsettings.json
"ConnectionStrings": {
"DefaultConnection": "Server=.;Database={{databaseName}};Trusted_Connection=True;MultipleActiveResultSets=true"
},
What is the best way to configure this value to be updated with the proper connection string
