Skip to content

Commit

Permalink
the serilog service methods make splitted
Browse files Browse the repository at this point in the history
  • Loading branch information
Onurcan Yılmaz committed Aug 14, 2021
1 parent cd8f340 commit 8d3b40c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ElasticLoggingService/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
var exception = context.Features.Get<IExceptionHandlerPathFeature>().Error;
var result = JsonConvert.SerializeObject(new { error = exception.Message });
context.Response.ContentType = "application/json";
logger.Log(LogLevel.Critical, exception, exception.Message);

WriteExceptionRequestLog(new LogRequest
{
Exception = exception,
LogLevel = LogLevel.Critical,
Message = exception.Message
});

await WriteAsync(context, result);
}));

Expand Down Expand Up @@ -88,10 +95,15 @@ async Task<LogRequest> GetLogRequestObjectAsync(Stream body)
}
}

void WriteRequestLog(LogRequest request)
void WriteExceptionRequestLog(LogRequest request)
{
logger.Log(request.LogLevel, request.Exception, request.Message);
}

void WriteRequestLog(LogRequest request)
{
logger.Log(request.LogLevel, request.Message);
}
}
}
}

0 comments on commit 8d3b40c

Please sign in to comment.