Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static void LogMessage(ILogger<KafkaProducer> log, LogMessage message)

private static void LogError(ILogger<KafkaProducer> log, Error error)
{
log.LogWarning("Kafka error with {code} and {reason}.", error.Code, error.Reason);
LogMessages.LogKafkaError(log, error.Code, error.Reason);
}

public async Task SendAsync(KafkaMessageRequest job,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public async Task EnhanceAsync(UploadAssetCommand command,
}
catch (Exception ex)
{
log.LogError(ex, "Failed to enrich asset.");
LogMessages.LogFailedToEnrichAsset(log, ex);
}
}

Expand Down
19 changes: 19 additions & 0 deletions backend/extensions/Squidex.Extensions/LogMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using Microsoft.Extensions.Logging;

namespace Squidex.Extensions;

internal static partial class LogMessages
{
[LoggerMessage(Level = LogLevel.Warning, Message = "Kafka error with {code} and {reason}.")]
public static partial void LogKafkaError(ILogger logger, object code, string reason);

[LoggerMessage(Level = LogLevel.Error, Message = "Failed to enrich asset.")]
public static partial void LogFailedToEnrichAsset(ILogger logger, Exception exception);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using Microsoft.Extensions.Logging;

namespace Squidex.Infrastructure.Counts;

internal static partial class LogMessages
{
[LoggerMessage(Level = LogLevel.Error, Message = "Failed to update count for collection {collection}.")]
public static partial void LogFailedToUpdateCount(ILogger logger, string collection, Exception exception);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private async Task RefreshSilentAsync(string key, long cachedCount, Func<Cancell
}
catch (Exception ex)
{
log.LogError(ex, "Failed to update count for collection {collection}.", collectionName);
LogMessages.LogFailedToUpdateCount(log, collectionName, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public IAsyncEnumerable<JobResult> CreateJobsAsync(Envelope<IEvent> @event, Rule
CreateJobs(@event, context, states, ct)
.Catch(ex =>
{
log.LogError(ex, "Failed to create rule job.");
LogMessages.LogFailedToCreateRuleJob(log, ex);

return states.Select(state => JobResult.Skipped(state.Rule, SkipReason.Failed));
});
Expand Down Expand Up @@ -237,7 +237,7 @@ private async IAsyncEnumerable<JobResult> CreateJobs(Envelope<IEvent> @event, Ru
CreateTriggerJobs(typed, triggerHandler, rulesByTrigger, context, ct)
.Catch(ex =>
{
log.LogError(ex, "Failed to create rule jobs from trigger.");
LogMessages.LogFailedToCreateRuleJobsFromTrigger(log, ex);

return states.Select(state => JobResult.Skipped(state.Rule, SkipReason.Failed));
});
Expand All @@ -263,7 +263,7 @@ private async IAsyncEnumerable<JobResult> CreateTriggerJobs(Envelope<AppEvent> @
CreateEventJobs(@event, enrichedEvent, triggerHandler, states, context)
.Catch(ex =>
{
log.LogError(ex, "Failed to create rule jobs from event.");
LogMessages.LogFailedToCreateRuleJobsFromEvent(log, ex);

return states.Select(state =>
new JobResult
Expand Down
22 changes: 22 additions & 0 deletions backend/src/Squidex.Domain.Apps.Core.Operations/LogMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using Microsoft.Extensions.Logging;

namespace Squidex.Domain.Apps.Core;

internal static partial class LogMessages
{
[LoggerMessage(Level = LogLevel.Error, Message = "Failed to create rule job.")]
public static partial void LogFailedToCreateRuleJob(ILogger logger, Exception exception);

[LoggerMessage(Level = LogLevel.Error, Message = "Failed to create rule jobs from trigger.")]
public static partial void LogFailedToCreateRuleJobsFromTrigger(ILogger logger, Exception exception);

[LoggerMessage(Level = LogLevel.Error, Message = "Failed to create rule jobs from event.")]
public static partial void LogFailedToCreateRuleJobsFromEvent(ILogger logger, Exception exception);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async Task PublishAsync(SquidexCommand command)
}
catch (Exception ex)
{
log.LogError(ex, "Failed to delete asset recursively.");
LogMessages.LogFailedToDeleteAssetRecursively(log, ex);
}
}

Expand Down
8 changes: 4 additions & 4 deletions backend/src/Squidex.Domain.Apps.Entities/Backup/RestoreJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public async Task RunAsync(JobRunContext context,
await context.LogAsync(" * Restore all objects like app, schemas and contents");
await context.LogAsync(" * Complete the restore operation for all objects");
await context.FlushAsync();
log.LogInformation("Backup with job id {backupId} with from URL '{url}' started.", context.Job.Id, state.Url);
LogMessages.LogRestoreJobStarted(log, context.Job.Id, state.Url);

state.Reader = await DownloadAsync(context, state, ct);

Expand Down Expand Up @@ -147,7 +147,7 @@ public async Task RunAsync(JobRunContext context,
await AssignContributorAsync(context, state);
await context.LogAsync("Completed, Yeah!");

log.LogInformation("Backup with job id {backupId} from URL '{url}' completed.", context.Job.Id, state.Url);
LogMessages.LogRestoreJobCompleted(log, context.Job.Id, state.Url);
}
catch (Exception ex)
{
Expand All @@ -168,7 +168,7 @@ public async Task RunAsync(JobRunContext context,

await context.LogAsync(message);

log.LogError(ex, "Backup with job id {backupId} from URL '{url}' failed.", context.Job.Id, state.Url);
LogMessages.LogRestoreJobFailed(log, context.Job.Id, state.Url, ex);
throw;
}
finally
Expand Down Expand Up @@ -231,7 +231,7 @@ private async Task CleanupAsync(State state)
}
catch (Exception ex)
{
log.LogError(ex, "Failed to clean up restore.");
LogMessages.LogFailedToCleanUpRestore(log, ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public ValueTask OnDocumentLoadedAsync(DocumentLoadEvent @event)
catch (Exception ex)
{
// We are in an extra task, so the exception would be probably swallowed.
log.LogError(ex, "Failed to handle yjs event.");
LogMessages.LogFailedToHandleYjsEvent(log, ex);
throw;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,13 @@ private async Task SendEmailAsync(string template, string emailSubj, string emai
{
if (string.IsNullOrWhiteSpace(emailBody))
{
log.LogWarning("Cannot send email to {email}: No email subject configured for template {template}.", template, user.Email);
LogMessages.LogNoEmailSubjectConfigured(log, template, user.Email);
return;
}

if (string.IsNullOrWhiteSpace(emailSubj))
{
log.LogWarning("Cannot send email to {email}: No email body configured for template {template}.", template, user.Email);
LogMessages.LogNoEmailBodyConfigured(log, template, user.Email);
return;
}

Expand All @@ -146,7 +146,7 @@ private async Task SendEmailAsync(string template, string emailSubj, string emai
}
catch (Exception ex)
{
log.LogError(ex, "Failed to send notification to {email}.", user.Email);
LogMessages.LogFailedToSendNotification(log, user.Email, ex);
throw;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task PublishAsync(
}
catch (Exception ex)
{
log.LogError(ex, "Failed to query scheduled status changes-");
LogMessages.LogFailedToQueryScheduledStatusChanges(log, ex);
}
}

Expand Down Expand Up @@ -88,7 +88,7 @@ private async Task TryPublishAsync(Content content)
}
catch (Exception ex)
{
log.LogError(ex, "Failed to execute scheduled status change for content '{contentId}'.", content.Id);
LogMessages.LogFailedToExecuteScheduledStatusChange(log, content.Id, ex);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public static void HandleError(this ExecutionOptions options, IServiceProvider s

if (!string.IsNullOrWhiteSpace(fieldName))
{
log.LogError(context.OriginalException, "Failed to resolve field {field}.", fieldName);
LogMessages.LogFailedToResolveField(log, fieldName, context.OriginalException);
}
else
{
log.LogError(context.OriginalException, "Failed to resolve execute query.");
LogMessages.LogFailedToResolveQuery(log, context.OriginalException);
}

if (context.OriginalException is ValidationException or DomainException)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ private async Task UpsertUserAsync(IUser user)
}
catch (NotifoException ex)
{
log.LogError(ex, "Failed to register user in notifo: {details}.", ex.ToString());
LogMessages.LogFailedToRegisterUserInNotifoWithDetails(log, ex.ToString(), ex);
}
catch (Exception ex)
{
log.LogError(ex, "Failed to register user in notifo.");
LogMessages.LogFailedToRegisterUserInNotifo(log, ex);
}
}

Expand Down Expand Up @@ -191,11 +191,11 @@ public async Task HandleEventsAsync(IEnumerable<(Envelope<IEvent> AppEvent, Hist
}
catch (NotifoException ex)
{
log.LogError(ex, "Failed to push user to notifo: {details}.", ex.ToString());
LogMessages.LogFailedToPushUserToNotifoWithDetails(log, ex.ToString(), ex);
}
catch (Exception ex)
{
log.LogError(ex, "Failed to push user to notifo.");
LogMessages.LogFailedToPushUserToNotifo(log, ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ public async Task On(Envelope<IEvent> @event)

if (assigner == null)
{
log.LogWarning("Failed to invite user: Assigner {assignerId} not found.", assignerId);
LogMessages.LogInvitationAssignerNotFound(log, assignerId);
return default;
}

var assignee = await userResolver.FindByIdAsync(assigneeId, ct);

if (assignee == null)
{
log.LogWarning("Failed to invite user: Assignee {assigneeId} not found.", assigneeId);
LogMessages.LogInvitationAssigneeNotFound(log, assigneeId);
return default;
}

Expand Down
10 changes: 5 additions & 5 deletions backend/src/Squidex.Domain.Apps.Entities/Jobs/JobProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task LoadAsync(
if (pending.Any())
{
// This should actually never happen, so we log with warning.
log.LogWarning("Removed unfinished jobs for owner {ownerId} after start.", ownerId);
LogMessages.LogRemovedUnfinishedJobs(log, ownerId);

foreach (var job in pending.ToList())
{
Expand All @@ -81,7 +81,7 @@ public Task DeleteAsync(DomainId jobId)
{
return scheduler.ScheduleAsync(async _ =>
{
log.LogInformation("Clearing jobs for owner {ownerId}.", ownerId);
LogMessages.LogClearingJobs(log, ownerId);

var job = state.Value.Jobs.Find(x => x.Id == jobId);

Expand All @@ -105,7 +105,7 @@ public Task ClearAsync()
{
return scheduler.ScheduleAsync(async _ =>
{
log.LogInformation("Clearing jobs for owner {ownerId}.", ownerId);
LogMessages.LogClearingJobs(log, ownerId);

foreach (var job in state.Value.Jobs)
{
Expand Down Expand Up @@ -164,7 +164,7 @@ public Task RunAsync(JobRequest request,
OwnerId = ownerId,
};

log.LogInformation("Starting new backup with backup id '{backupId}' for owner {ownerId}.", context.Job.Id, ownerId);
LogMessages.LogStartingJob(log, context.Job.Id, ownerId);

state.Value.Jobs.Insert(0, context.Job);
try
Expand Down Expand Up @@ -221,7 +221,7 @@ private async Task ProcessAsync(JobRunContext context, IJobRunner runner,
}
catch (Exception ex)
{
log.LogError(ex, "Failed to run job with ID {jobId}.", context.Job.Id);
LogMessages.LogFailedToRunJob(log, context.Job.Id, ex);

await SetStatusAsync(context, JobStatus.Failed);
}
Expand Down
Loading
Loading