Skip to content

Commit

Permalink
Merge pull request #4 from redbridge-uk/feature/logging
Browse files Browse the repository at this point in the history
Feature/logging
  • Loading branch information
binarysenator authored Mar 22, 2023
2 parents ff0a396 + bf22711 commit 2dbd0b3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override void OnException(HttpActionExecutedContext actionExecutedContext
};

actionExecutedContext.Response = response;
_logger.LogError(actionExecutedContext.Exception.Message, actionExecutedContext.Exception);
_logger.LogError(actionExecutedContext.Exception, actionExecutedContext.Exception.Message);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Redbridge.WebApi/Filters/UnhandledExceptionLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellat
_logger.LogInformation("Logging (only) unhandled exceptions...");

if (context.Exception != null)
_logger.LogError(context.Exception.Message, context.Exception);
_logger.LogError(context.Exception, context.Exception.Message);

return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Net.Http;
using System.Web.Http.Filters;
using Microsoft.Extensions.Logging;
using Redbridge.Diagnostics;
using Redbridge.Exceptions;

namespace Redbridge.WebApi.Filters
Expand All @@ -20,9 +19,7 @@ public override void OnException(HttpActionExecutedContext actionExecutedContext
{
_logger.LogInformation("Checking exception for user not authorized exception filtering....");

var exception = actionExecutedContext.Exception as UserNotAuthorizedException;

if (exception != null)
if (actionExecutedContext.Exception is UserNotAuthorizedException exception)
{
var response = new HttpResponseMessage(HttpStatusCode.Forbidden)
{
Expand Down

0 comments on commit 2dbd0b3

Please sign in to comment.