Global Exception Handling


public class GlobalExceptionHandling
{
    public async Task InvokeAsync(HttpContext context, RequestDelegate next)
    {
        try
        {
            await next(context);
        }
        catch (Exception ex)
        {
            await HandleExceptionAsync(context, ex);
        }
    }
}


Structured Logging with Serilog

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Information()
    .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
    .Enrich.FromLogContext()
    .WriteTo.Console()
    .WriteTo.File("ApiLogs/log-.txt", rollingInterval: RollingInterval.Day)
    .CreateLogger();


Application Insights Integration 


•    Custom telemetry for business events
•    Performance monitoring for API endpoints
•    Error tracking with stack traces
•    User analytics for UI interactions