I’m trying to use a Serilog enricher to see if the DTO and/or type which has an attribute but the DTO always comes back null. Is there a way to get this? I’ve tried adding to the Items collection in the exception handler but it always empty when it gets to the enricher.
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Is(AppSettings.Get<LogEventLevel>("logLevel", LogEventLevel.Error))
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.Enrich.WithDynamicProperty("SendAlert", () =>
{
var req = HostContext.TryGetCurrentRequest();
if (req != null && req.GetType().HasAttribute<AuthenticateAttribute>()) // req.Dto is null
{
var a = req.GetType().FirstAttribute<LogAlertAttribute>();
if (a.SendAlert)
return "true";
}
return null;
}, minimumLevel: LogEventLevel.Error);
this.ServiceExceptionHandlers.Add((httpReq, request, exception) =>
{
//log your exceptions here
Log.Error(exception, "ServiceStack exception handler");
return null; //continue with default Error Handling
//or return your own custom response
//return DtoUtils.CreateErrorResponse(request, exception);
});