diff --git a/src/Tgstation.Server.Host/Core/ApplicationBuilderExtensions.cs b/src/Tgstation.Server.Host/Core/ApplicationBuilderExtensions.cs
index becd3e5ad6..971d018f73 100644
--- a/src/Tgstation.Server.Host/Core/ApplicationBuilderExtensions.cs
+++ b/src/Tgstation.Server.Host/Core/ApplicationBuilderExtensions.cs
@@ -1,6 +1,9 @@
using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
using System;
using System.Globalization;
using Tgstation.Server.Api.Models;
@@ -12,6 +15,13 @@ namespace Tgstation.Server.Host.Core
///
static class ApplicationBuilderExtensions
{
+ ///
+ /// Gets a from a given
+ ///
+ /// The to get the from
+ /// A new
+ static ILogger GetLogger(HttpContext httpContext) => httpContext.RequestServices.GetRequiredService>();
+
///
/// Return a for s
///
@@ -22,12 +32,14 @@ namespace Tgstation.Server.Host.Core
throw new ArgumentNullException(nameof(applicationBuilder));
applicationBuilder.Use(async (context, next) =>
{
+ var logger = GetLogger(context);
try
{
await next().ConfigureAwait(false);
}
catch (DbUpdateException e)
{
+ logger.LogDebug("Database conflict: {0}", e.Message);
await new ConflictObjectResult(new ErrorMessage { Message = String.Format(CultureInfo.InvariantCulture, "A database conflict has occurred: {0}", (e.InnerException ?? e).Message) }).ExecuteResultAsync(new ActionContext
{
HttpContext = context
@@ -46,11 +58,15 @@ namespace Tgstation.Server.Host.Core
throw new ArgumentNullException(nameof(applicationBuilder));
applicationBuilder.Use(async (context, next) =>
{
+ var logger = GetLogger(context);
try
{
await next().ConfigureAwait(false);
}
- catch (OperationCanceledException) { }
+ catch (OperationCanceledException)
+ {
+ logger.LogDebug("Request cancelled!");
+ }
});
}
}