mirror of
https://github.com/SoDOff-Project/sodoff.git
synced 2025-10-11 08:18:49 -07:00
add log request on exception
This commit is contained in:
parent
4544c6a3d1
commit
626764adb6
@ -1,6 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||
using sodoff.Model;
|
||||
using sodoff.Services;
|
||||
using sodoff.Utils;
|
||||
using System.Xml;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@ -10,6 +11,7 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddControllers(options => {
|
||||
options.OutputFormatters.Add(new XmlSerializerOutputFormatter(new XmlWriterSettings() { OmitXmlDeclaration = false }));
|
||||
options.OutputFormatters.RemoveType<HttpNoContentOutputFormatter>();
|
||||
options.Filters.Add<LogRequestOnError>();
|
||||
});
|
||||
builder.Services.AddDbContext<DBContext>();
|
||||
builder.Services.AddScoped<KeyValueService>();
|
||||
|
12
src/Util/LogRequestOnError.cs
Normal file
12
src/Util/LogRequestOnError.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace sodoff.Utils;
|
||||
|
||||
public class LogRequestOnError : IAsyncExceptionFilter {
|
||||
public async Task OnExceptionAsync(ExceptionContext context) {
|
||||
Console.WriteLine(string.Format("Exception caused by: {0}", context.HttpContext.Request.Path));
|
||||
foreach (var field in context.HttpContext.Request.Form)
|
||||
Console.WriteLine(string.Format(" {0}", field).Replace("\r", "\n"));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user