mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 00:52:49 -05:00
[PM-13098] Use ILogger.BeginScope
For Better Scopes (#4740)
* Use `ILogger.BeginScope` For Better Scopes * Format * Remove Behind Feature Flag
This commit is contained in:
@ -48,7 +48,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc.Localization;
|
||||
@ -60,7 +59,6 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Serilog.Context;
|
||||
using StackExchange.Redis;
|
||||
using NoopRepos = Bit.Core.Repositories.Noop;
|
||||
using Role = Bit.Core.Entities.Role;
|
||||
@ -540,31 +538,7 @@ public static class ServiceCollectionExtensions
|
||||
public static void UseDefaultMiddleware(this IApplicationBuilder app,
|
||||
IWebHostEnvironment env, GlobalSettings globalSettings)
|
||||
{
|
||||
string GetHeaderValue(HttpContext httpContext, string header)
|
||||
{
|
||||
if (httpContext.Request.Headers.ContainsKey(header))
|
||||
{
|
||||
return httpContext.Request.Headers[header];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Add version information to response headers
|
||||
app.Use(async (httpContext, next) =>
|
||||
{
|
||||
using (LogContext.PushProperty("IPAddress", httpContext.GetIpAddress(globalSettings)))
|
||||
using (LogContext.PushProperty("UserAgent", GetHeaderValue(httpContext, "user-agent")))
|
||||
using (LogContext.PushProperty("DeviceType", GetHeaderValue(httpContext, "device-type")))
|
||||
using (LogContext.PushProperty("Origin", GetHeaderValue(httpContext, "origin")))
|
||||
{
|
||||
httpContext.Response.OnStarting((state) =>
|
||||
{
|
||||
httpContext.Response.Headers.Append("Server-Version", AssemblyHelpers.GetVersion());
|
||||
return Task.FromResult(0);
|
||||
}, null);
|
||||
await next.Invoke();
|
||||
}
|
||||
});
|
||||
app.UseMiddleware<RequestLoggingMiddleware>();
|
||||
}
|
||||
|
||||
public static void UseForwardedHeaders(this IApplicationBuilder app, IGlobalSettings globalSettings)
|
||||
|
Reference in New Issue
Block a user