Logging refactor

This commit is contained in:
Michał Zieliński
2025-06-02 18:53:25 +02:00
parent b800890320
commit ab3310a0c2
25 changed files with 682 additions and 750 deletions

View File

@@ -1,4 +1,3 @@
using FirebaseAdmin;
using Google.Apis.Auth.OAuth2;
using Google.Cloud.Firestore;
using Microsoft.AspNetCore.Authentication.JwtBearer;
@@ -87,24 +86,10 @@ builder.Services.AddSingleton<SpreadsheetsResource.ValuesResource>(provider =>
return valuesResource;
});
var fileName = "diunabi-admin-firebase.json";
#if DEBUG
fileName = "diunabi-admin-firebase-Development.json";
#endif
var credentialPath = Path.Combine(Directory.GetCurrentDirectory(), fileName);
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", credentialPath);
FirebaseAdmin.FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.GetApplicationDefault()
});
builder.Services.AddSingleton(FirestoreDb.Create("diunabi-admin"));
builder.Services.AddSingleton<PluginManager>();
var app = builder.Build();
// ✅ DODAJ SERILOG REQUEST LOGGING
app.UseSerilogRequestLogging(options =>
{
options.MessageTemplate = "HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000} ms";
@@ -113,20 +98,17 @@ app.UseSerilogRequestLogging(options =>
diagnosticContext.Set("RequestHost", httpContext.Request.Host.Value);
diagnosticContext.Set("RequestScheme", httpContext.Request.Scheme);
// ✅ POPRAW NULLABLE WARNING
var userAgent = httpContext.Request.Headers.UserAgent.FirstOrDefault();
if (!string.IsNullOrEmpty(userAgent))
{
diagnosticContext.Set("UserAgent", userAgent);
}
// Dodaj więcej użytecznych właściwości
diagnosticContext.Set("RemoteIP", httpContext.Connection.RemoteIpAddress?.ToString() ?? "unknown");
diagnosticContext.Set("RequestContentType", httpContext.Request.ContentType ?? "none");
};
});
// Załaduj pluginy - z logowaniem
var pluginManager = app.Services.GetRequiredService<PluginManager>();
var executablePath = Assembly.GetExecutingAssembly().Location;
var executableDir = Path.GetDirectoryName(executablePath)!;