Skip to content

Commit

Permalink
Adding Serilog config to AppConfig (#798)
Browse files Browse the repository at this point in the history
Moving config from appsettings to Azure App Config, and adding Log
Analytics sink for Serilog.
  • Loading branch information
Eirik Sander-Fjeld authored Oct 24, 2022
1 parent 8aea378 commit 77749b6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 38 deletions.
24 changes: 10 additions & 14 deletions backend/api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,10 @@
options.AddFusionRoles();
options.ApplicationMode = true;
});
var serilogConfiguration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();

Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.ReadFrom.Configuration(serilogConfiguration)
.ReadFrom.Configuration(config)
.CreateBootstrapLogger();
builder.Services.AddApplicationInsightsTelemetry(appInsightTelemetryOptions);
builder.Services.AddScoped<ProjectService>();
Expand Down Expand Up @@ -182,20 +178,20 @@
builder.Services.AddScoped<SurfService>();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "JWTToken_Auth_API",
Title = "JWTToken_Auth_API",
Version = "v1"
});
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
{
Name = "Authorization",
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer",
BearerFormat = "JWT",
In = ParameterLocation.Header,
Name = "Authorization",
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer",
BearerFormat = "JWT",
In = ParameterLocation.Header,
Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 1safsfsdfdfd\"",
});
c.AddSecurityRequirement(new OpenApiSecurityRequirement {
Expand Down
1 change: 1 addition & 0 deletions backend/api/api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.5.0-dev-00359" />
<PackageReference Include="Serilog.Sinks.AzureAnalytics" Version="4.8.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
Expand Down
24 changes: 0 additions & 24 deletions backend/api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,5 @@
"gasExportPipelineLength": "E60"
}
}
},
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": {
"Default": "Verbose",
"Override": {
"Microsoft": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
}
},
"WriteTo": [
{"Name": "Console",
"Args": {
"restrictedToMinimumLevel": "Information"
}
},
{"Name": "File",
"Args": {
"path": "/logs/log-.txt",
"rollingInterval": "Day",
"restrictedToMinimumLevel": "Warning"
}
}
]
}
}

0 comments on commit 77749b6

Please sign in to comment.