Browse Source

Centralize remaining ILogger log statements in infrastructure and web

pull/1318/head
copilot-swe-agent[bot] 2 weeks ago
committed by GitHub
parent
commit
0adf66dae1
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      backend/src/Squidex.Infrastructure/Commands/Rebuilder.cs
  2. 3
      backend/src/Squidex.Infrastructure/LogMessages.cs
  3. 2
      backend/src/Squidex.Infrastructure/UsageTracking/BackgroundUsageTracker.cs
  4. 2
      backend/src/Squidex.Web/ApiExceptionFilterAttribute.cs
  5. 16
      backend/src/Squidex.Web/LogMessages.cs
  6. 2
      backend/src/Squidex.Web/Pipeline/ApiKeyHandler.cs
  7. 12
      backend/src/Squidex.Web/Pipeline/AppResolver.cs
  8. 10
      backend/src/Squidex.Web/Pipeline/TeamResolver.cs

2
backend/src/Squidex.Infrastructure/Commands/Rebuilder.cs

@ -105,7 +105,7 @@ public class Rebuilder(
}
catch (Exception ex)
{
log.LogWarning(ex, "Found corrupt domain object of type {type} with ID {id}.", typeof(T), id);
LogMessages.LogFoundCorruptDomainObject(log, typeof(T), id, ex);
Interlocked.Increment(ref handlerErrors);
}
}

3
backend/src/Squidex.Infrastructure/LogMessages.cs

@ -58,4 +58,7 @@ internal static partial class LogMessages
[LoggerMessage(Level = LogLevel.Error, Message = "Failed to repair snapshot for domain object of type {type} with ID {id}.")]
public static partial void LogFailedToRepairDomainObjectSnapshot(ILogger logger, Type type, DomainId id, Exception exception);
[LoggerMessage(Level = LogLevel.Warning, Message = "Found corrupt domain object of type {type} with ID {id}.")]
public static partial void LogFoundCorruptDomainObject(ILogger logger, Type type, DomainId id, Exception exception);
}

2
backend/src/Squidex.Infrastructure/UsageTracking/BackgroundUsageTracker.cs

@ -82,7 +82,7 @@ public sealed class BackgroundUsageTracker : DisposableObjectBase, IUsageTracker
}
catch (Exception ex)
{
log.LogError(ex, "Failed to track usage in background.");
LogMessages.LogTrackUsageFailed(log, ex);
}
finally
{

2
backend/src/Squidex.Web/ApiExceptionFilterAttribute.cs

@ -34,7 +34,7 @@ public sealed class ApiExceptionFilterAttribute : ActionFilterAttribute, IExcept
{
var log = context.HttpContext.RequestServices.GetRequiredService<ILogger<ApiExceptionFilterAttribute>>();
log.LogError(unhandled, "An unexpected exception has occurred.");
LogMessages.LogUnexpectedException(log, unhandled);
}
context.Result = GetResult(error);

16
backend/src/Squidex.Web/LogMessages.cs

@ -6,6 +6,7 @@
// ==========================================================================
using Microsoft.Extensions.Logging;
using Squidex.Infrastructure;
namespace Squidex.Web;
@ -16,4 +17,19 @@ internal static partial class LogMessages
[LoggerMessage(Level = LogLevel.Critical, Message = "Failed to send result.")]
public static partial void LogFailedToSendResult(ILogger logger, Exception exception);
[LoggerMessage(Level = LogLevel.Warning, Message = "Cannot find app with the given name {name}.")]
public static partial void LogCannotFindAppByName(ILogger logger, string name);
[LoggerMessage(Level = LogLevel.Warning, Message = "Authenticated user has no permission to access the app {name} with ID {id}.")]
public static partial void LogNoPermissionToAccessApp(ILogger logger, DomainId id, string name);
[LoggerMessage(Level = LogLevel.Warning, Message = "Cannot find team with the given id {id}.")]
public static partial void LogCannotFindTeamById(ILogger logger, string id);
[LoggerMessage(Level = LogLevel.Warning, Message = "Authenticated user has no permission to access the team with ID {id}.")]
public static partial void LogNoPermissionToAccessTeam(ILogger logger, DomainId id);
[LoggerMessage(Level = LogLevel.Error, Message = "Error while handling api key.")]
public static partial void LogErrorHandlingApiKey(ILogger logger, Exception exception);
}

2
backend/src/Squidex.Web/Pipeline/ApiKeyHandler.cs

@ -75,7 +75,7 @@ public sealed class ApiKeyHandler(
}
catch (Exception ex)
{
Logger.LogError(ex, "Error while handling api key.");
LogMessages.LogErrorHandlingApiKey(Logger, ex);
throw;
}

12
backend/src/Squidex.Web/Pipeline/AppResolver.cs

@ -41,7 +41,10 @@ public sealed class AppResolver(IAppProvider appProvider) : IAsyncActionFilter
{
var log = context.HttpContext.RequestServices?.GetService<ILogger<AppResolver>>();
log?.LogWarning("Cannot find app with the given name {name}.", appName);
if (log != null)
{
LogMessages.LogCannotFindAppByName(log, appName);
}
context.Result = new NotFoundResult();
return;
@ -97,9 +100,10 @@ public sealed class AppResolver(IAppProvider appProvider) : IAsyncActionFilter
{
var log = context.HttpContext.RequestServices?.GetService<ILogger<AppResolver>>();
log?.LogWarning("Authenticated user has no permission to access the app {name} with ID {id}.",
app.Id,
app.Name);
if (log != null)
{
LogMessages.LogNoPermissionToAccessApp(log, app.Id, app.Name);
}
context.Result = new NotFoundResult();
}

10
backend/src/Squidex.Web/Pipeline/TeamResolver.cs

@ -41,7 +41,10 @@ public sealed class TeamResolver(IAppProvider appProvider) : IAsyncActionFilter
{
var log = context.HttpContext.RequestServices?.GetService<ILogger<TeamResolver>>();
log?.LogWarning("Cannot find team with the given id {id}.", teamId);
if (log != null)
{
LogMessages.LogCannotFindTeamById(log, teamId);
}
context.Result = new NotFoundResult();
return;
@ -69,7 +72,10 @@ public sealed class TeamResolver(IAppProvider appProvider) : IAsyncActionFilter
{
var log = context.HttpContext.RequestServices?.GetService<ILogger<AppResolver>>();
log?.LogWarning("Authenticated user has no permission to access the team with ID {id}.", team.Id);
if (log != null)
{
LogMessages.LogNoPermissionToAccessTeam(log, team.Id);
}
context.Result = new NotFoundResult();
}

Loading…
Cancel
Save