Skip to content
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

fix(logging): reduce logging for requests #206

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace Eurofurence.App.Server.Web.Controllers
{
[Route("Api/[controller]")]
[AllowAnonymous]
public class DealersController : BaseController
{
private readonly IDealerService _dealerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.Expressions" Version="5.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" />
Expand Down
55 changes: 1 addition & 54 deletions src/Eurofurence.App.Server.Web/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Autofac;
using Eurofurence.App.Server.Services.Abstractions;
using Eurofurence.App.Server.Services.Abstractions.Fursuits;
using Eurofurence.App.Server.Web.Extensions;
using Eurofurence.App.Server.Web.Jobs;
using Eurofurence.App.Server.Web.Swagger;
Expand All @@ -15,7 +14,6 @@
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Context;
using Serilog.Events;
using Swashbuckle.AspNetCore.SwaggerUI;
using System;
using System.Text.Json;
Expand Down Expand Up @@ -359,58 +357,7 @@ public void Configure(
IHostApplicationLifetime appLifetime
)
{
var loggerConfiguration = new LoggerConfiguration().Enrich.FromLogContext();

var consoleLogLevel = env.IsDevelopment() ? LogEventLevel.Debug : LogEventLevel.Information;

loggerConfiguration
.WriteTo.Console(
restrictedToMinimumLevel: consoleLogLevel,
outputTemplate:
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{IPAddress}] [{Level}] {Message}{NewLine}{Exception}");

if (!string.IsNullOrEmpty(Configuration["auditLog"]))
{
loggerConfiguration
.WriteTo
.Logger(lc =>
lc.Filter
.ByIncludingOnly($"EventId.Id = {LogEvents.Audit.Id}")
.WriteTo.File(Configuration["auditLog"],
restrictedToMinimumLevel: LogEventLevel.Verbose,
outputTemplate:
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{IPAddress}] [{Level}] {Message}{NewLine}{Exception}"
)
);
}

var cgc = new CollectionGameConfiguration();
Configuration.GetSection(CollectionGameConfiguration.CollectionGame).Bind(cgc);

if (!string.IsNullOrEmpty(cgc.LogFile))
{
loggerConfiguration
.WriteTo
.Logger(lc =>
lc.Filter
.ByIncludingOnly($"EventId.Id = {LogEvents.CollectionGame.Id}")
.WriteTo.File(cgc.LogFile, (LogEventLevel)cgc.LogLevel)
);
}

if (!string.IsNullOrEmpty(Configuration["importLog"]))
{
loggerConfiguration
.WriteTo
.Logger(lc =>
lc.Filter
.ByIncludingOnly($"EventId.Id = {LogEvents.Import.Id}")
.WriteTo.File(Configuration["importLog"],
restrictedToMinimumLevel: LogEventLevel.Verbose
)
);
}

var loggerConfiguration = new LoggerConfiguration().ReadFrom.Configuration(Configuration);
Log.Logger = loggerConfiguration.CreateLogger();

loggerFactory
Expand Down
43 changes: 30 additions & 13 deletions src/Eurofurence.App.Server.Web/appsettings.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,36 @@
"ConnectionStrings": {
"Eurofurence": "Server=db; Port=3306; Database=ef_backend; user=root; SslMode=Preferred;"
},
"oAuth": {
"issuer": "EurofurenceAppWebApi",
"audience": "EurofurenceAppWebApi",
"secretKey": "LynxesAreAwesomeAndHaveFuzzyEartuftsAndThisIsTotallyNotTheTokenUsedInTheLiveEnvironment"
},
"wns": {
"clientId": "",
"clientSecret": "",
"targetTopic": "Debug"
"Serilog": {
"Using": [
"Serilog.Sinks.Console",
"Serilog.Sinks.File"
],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"System.Net.Http.HttpClient": "Warning"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{IPAddress}] {Message}{NewLine}{Exception}"
}
},
{
"Name": "File",
"Args": {
"path": "/tmp/log.txt"
}
}
],
"Enrich": [
"FromLogContext"
]
},
"firebase": {
"googleServiceCredentialKeyFile": "firebase.json",
Expand All @@ -54,10 +75,6 @@
"accessToken": "",
"proxy": ""
},
"collectionGame": {
"logLevel": 1,
"logFile": "/tmp/collect.log"
},
"artistAlley": {
"telegram": {
"adminGroupChatId": "",
Expand Down