Bypassing the signalR loggin in logger middleware

This commit is contained in:
ashutosh.nehete 2025-12-13 09:54:48 +05:30
parent 6f6292b167
commit e0656b6734
2 changed files with 17 additions and 15 deletions

View File

@ -130,15 +130,6 @@ namespace Marco.Pms.Services.Controllers
var featureDetailsVM = _mapper.Map<FeatureDetailsVM>(featureDetails);
//var featureDetailsVM = new FeatureDetailsVM
//{
// Id = featureDetails.Id,
// Modules = _mapper.Map<ModulesDetailsVM>(featureDetails.Modules),
// Reports = featureDetails.Reports,
// Supports = featureDetails.Supports,
// SubscriptionCheckList = featureDetails.SubscriptionCheckList
//};
if (featureDetailsVM.Modules?.Attendance != null)
featureDetailsVM.Modules.Attendance.Features = features.Where(f => attendanceFeatures.Contains(f.Id)).ToList();

View File

@ -1,6 +1,6 @@
using MarcoBMS.Services.Service;
using Serilog.Context;
using Serilog.Context;
using System.Diagnostics;
using System.Security.Claims;
namespace MarcoBMS.Services.Middleware
{
@ -8,22 +8,32 @@ namespace MarcoBMS.Services.Middleware
{
private readonly RequestDelegate _next;
private readonly ILogger<LoggingMiddleware> _logger;
private readonly ILoggingService _loggingService;
//private readonly UserHelper _userHelper;
public LoggingMiddleware(RequestDelegate next, ILogger<LoggingMiddleware> logger, ILoggingService loggingService)
private readonly List<string> _ignoredPaths = new List<string>
{
"/hubs/marco",
"/hubs/marco/negotiate",
"/swagger"
};
public LoggingMiddleware(RequestDelegate next, ILogger<LoggingMiddleware> logger)
{
_next = next;
_logger = logger;
//_userHelper = userHelper;
_loggingService = loggingService;
}
public async Task Invoke(HttpContext context)
{
if (_ignoredPaths.Any(path => context.Request.Path.StartsWithSegments(path, StringComparison.OrdinalIgnoreCase)))
{
await _next(context);
return;
}
var stopwatch = Stopwatch.StartNew();
var response = context.Response;
var request = context.Request;
var tenantId = context.User.FindFirst("TenantId")?.Value;
var userId = context.User.FindFirstValue(ClaimTypes.NameIdentifier);
string origin = request.Headers["Origin"].FirstOrDefault() ?? "";
using (LogContext.PushProperty("TenantId", tenantId))
@ -35,6 +45,7 @@ namespace MarcoBMS.Services.Middleware
using (LogContext.PushProperty("RequestPath", request.Path))
using (LogContext.PushProperty("Origin", origin))
using (LogContext.PushProperty("LogOrigin", "ASP .NET Api"))
using (LogContext.PushProperty("UserId", userId))