static dynamic OnErrorHook(NancyContext context, Exception ex) { if (!context.Items.ContainsKey("RequestId") || !context.Items.ContainsKey("Stopwatch")) { return(null); } var stopwatch = (Stopwatch)context.Items["Stopwatch"]; stopwatch.Stop(); var requestId = (string)context.Items["RequestId"]; var errorLogData = new ErrorLogData(); errorLogData.RequestId = requestId; errorLogData.Duration = stopwatch.ElapsedMilliseconds; errorLogData.ResolvedPath = context.ResolvedRoute.Description.Path; errorLogData.RequestedPath = context.Request.Path; errorLogData.Method = context.Request.Method; errorLogData.ResolvedRouteParameters = NancyContextExtensions.ReadDynamicDictionary(context.Parameters); var logger = Log.ForContext(new ErrorLogEnricher(errorLogData, options)); logger.Error(ex, "Server Error at {Method} {Path}", errorLogData.Method, errorLogData.RequestedPath); return(null); }
public ErrorLogEnricher(ErrorLogData errorLog, NancySerilogOptions options) { this.errorLog = errorLog; this.options = options; if (this.options.IgnoreErrorLogFields == null) { this.options.IgnoreErrorLogFields = new FieldChooser <ErrorLogData>(); } }
static dynamic OnErrorHook(NancyContext context, Exception ex) { if (!context.Items.ContainsKey("RequestId") || !context.Items.ContainsKey("Stopwatch")) { return(null); } var stopwatch = (Stopwatch)context.Items["Stopwatch"]; stopwatch.Stop(); var requestId = (string)context.Items["RequestId"]; var errorLogData = new ErrorLogData(); errorLogData.RequestId = requestId; errorLogData.Duration = stopwatch.ElapsedMilliseconds; errorLogData.ResolvedPath = context.ResolvedRoute.Description.Path; errorLogData.RequestedPath = context.Request.Path; var logger = Log.ForContext(new ErrorLogEnricher(errorLogData)); logger.Error(ex, "Server Error"); return(null); }
public ErrorLogEnricher(ErrorLogData errorLog) { this.errorLog = errorLog; }