Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/Squidex.Assets.FTP/FTPAssetStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task InitializeAsync(
pool.Return(client);
}

log.LogInformation("Initialized with {path}", options.Path);
LogMessages.InitializedWithPath(log, options.Path);
}

public async Task<long> GetSizeAsync(string fileName,
Expand Down
16 changes: 16 additions & 0 deletions assets/Squidex.Assets.FTP/LogMessages.cs
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.Assets.FTP;

internal static partial class LogMessages
{
[LoggerMessage(EventId = 1, Level = LogLevel.Information, Message = "Initialized with {path}")]
public static partial void InitializedWithPath(ILogger logger, string path);
}
6 changes: 3 additions & 3 deletions assets/Squidex.Assets.ResizeService/ImageResizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private async Task BlurAsync(HttpContext context)
catch (Exception ex)
{
var log = context.RequestServices.GetRequiredService<ILogger<ImageResizer>>();
log.LogError(ex, "Failed to orient image.");
LogMessages.FailedToOrientImage(log, ex);

context.Response.StatusCode = 400;
}
Expand All @@ -64,7 +64,7 @@ await assetThumbnailGenerator.FixAsync(
catch (Exception ex)
{
var log = context.RequestServices.GetRequiredService<ILogger<ImageResizer>>();
log.LogError(ex, "Failed to orient image.");
LogMessages.FailedToOrientImage(log, ex);

context.Response.StatusCode = 400;
}
Expand All @@ -89,7 +89,7 @@ await assetThumbnailGenerator.CreateThumbnailAsync(
catch (Exception ex)
{
var log = context.RequestServices.GetRequiredService<ILogger<ImageResizer>>();
log.LogError(ex, "Failed to resize image.");
LogMessages.FailedToResizeImage(log, ex);

context.Response.StatusCode = 400;
}
Expand Down
19 changes: 19 additions & 0 deletions assets/Squidex.Assets.ResizeService/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.Assets.ResizeService;

internal static partial class LogMessages
{
[LoggerMessage(EventId = 1, Level = LogLevel.Error, Message = "Failed to orient image.")]
public static partial void FailedToOrientImage(ILogger logger, Exception exception);

[LoggerMessage(EventId = 2, Level = LogLevel.Error, Message = "Failed to resize image.")]
public static partial void FailedToResizeImage(ILogger logger, Exception exception);
}
2 changes: 1 addition & 1 deletion assets/Squidex.Assets/FolderAssetStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task InitializeAsync(
}

await this.UploadTestAssetAsync(ct);
log.LogInformation("Initialized with {folder}", directory.FullName);
LogMessages.InitializedWithFolder(log, directory.FullName);
}
catch (Exception ex)
{
Expand Down
16 changes: 16 additions & 0 deletions assets/Squidex.Assets/LogMessages.cs
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.Assets;

internal static partial class LogMessages
{
[LoggerMessage(EventId = 1, Level = LogLevel.Information, Message = "Initialized with {folder}")]
public static partial void InitializedWithFolder(ILogger logger, string folder);
}
12 changes: 4 additions & 8 deletions flows/Squidex.Flows/CronJobs/Internal/DefaultCronJobManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ public async Task UpdateAllAsync(
if (!TryGetCronExpression(cronJob.CronExpression, false, out var expression))
{
failedJobs.TryAdd(cronJob.Id, true);
log.LogWarning("Failed parse expression '{expression}' for id '{id}'",
cronJob.Id,
cronJob.CronExpression);
LogMessages.FailedToParseExpression(log, cronJob.CronExpression, cronJob.Id);
continue;
}

Expand All @@ -85,9 +83,7 @@ public async Task UpdateAllAsync(

if (next == default)
{
log.LogWarning("Failed to get next occurrency for cron job '{id}' and expression '{expression}'",
cronJob.Id,
cronJob.CronExpression);
LogMessages.FailedToGetNextOccurrency(log, cronJob.Id, cronJob.CronExpression);
continue;
}

Expand All @@ -96,7 +92,7 @@ public async Task UpdateAllAsync(
catch (Exception ex)
{
failedJobs.TryAdd(cronJob.Id, true);
log.LogError(ex, "Failed to handle cron job with id '{id}'", cronJob.Id);
LogMessages.FailedToHandleCronJob(log, ex, cronJob.Id);
}
}

Expand All @@ -111,7 +107,7 @@ public async Task UpdateAllAsync(
}
catch (Exception ex)
{
log.LogCritical(ex, "Failed to reschedule cron jobs.");
LogMessages.FailedToRescheduleCronJobs(log, ex);
foreach (var (id, _) in currentUpdates)
{
failedJobs.TryAdd(id, true);
Expand Down
25 changes: 25 additions & 0 deletions flows/Squidex.Flows/CronJobs/Internal/LogMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using Microsoft.Extensions.Logging;

namespace Squidex.Flows.CronJobs.Internal;

internal static partial class LogMessages
{
[LoggerMessage(EventId = 1, Level = LogLevel.Warning, Message = "Failed to parse expression '{expression}' for id '{id}'")]
public static partial void FailedToParseExpression(ILogger logger, string expression, string id);

[LoggerMessage(EventId = 2, Level = LogLevel.Warning, Message = "Failed to get next occurrence for cron job '{id}' and expression '{expression}'")]
public static partial void FailedToGetNextOccurrency(ILogger logger, string id, string expression);

[LoggerMessage(EventId = 3, Level = LogLevel.Error, Message = "Failed to handle cron job with id '{id}'")]
public static partial void FailedToHandleCronJob(ILogger logger, Exception exception, string id);

[LoggerMessage(EventId = 4, Level = LogLevel.Critical, Message = "Failed to reschedule cron jobs.")]
public static partial void FailedToRescheduleCronJobs(ILogger logger, Exception exception);
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private async Task HandleCallbacksAsync(FlowExecutionState<TContext> state,
}
catch (Exception ex)
{
log.LogError(ex, "Failed to execute {callback}.", callback);
LogMessages.FailedToExecuteCallback(log, ex, callback);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions flows/Squidex.Flows/Internal/Execution/FlowExecutionWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task QueryAsync(
}
catch (Exception ex)
{
log.LogError(ex, "Failed to query rule events.");
LogMessages.FailedToQueryRuleEvents(log, ex);
}
}

Expand All @@ -91,7 +91,7 @@ public async Task HandleAsync(FlowExecutionState<TContext> state,
}
catch (Exception ex)
{
log.LogError(ex, "Failed to execute flow.");
LogMessages.FailedToExecuteFlow(log, ex);
}
finally
{
Expand Down
22 changes: 22 additions & 0 deletions flows/Squidex.Flows/Internal/Execution/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.Flows.Internal.Execution;

internal static partial class LogMessages
{
[LoggerMessage(EventId = 1, Level = LogLevel.Error, Message = "Failed to execute {callback}.")]
public static partial void FailedToExecuteCallback(ILogger logger, Exception exception, object callback);

[LoggerMessage(EventId = 2, Level = LogLevel.Error, Message = "Failed to query rule events.")]
public static partial void FailedToQueryRuleEvents(ILogger logger, Exception exception);

[LoggerMessage(EventId = 3, Level = LogLevel.Error, Message = "Failed to execute flow.")]
public static partial void FailedToExecuteFlow(ILogger logger, Exception exception);
}
16 changes: 16 additions & 0 deletions hosting/Squidex.Hosting.Abstractions/LogMessages.cs
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.Hosting;

internal static partial class LogMessages
{
[LoggerMessage(EventId = 1, Level = LogLevel.Warning, Message = "Failed to execute timer.")]
public static partial void FailedToExecuteTimer(ILogger logger, Exception exception);
}
5 changes: 4 additions & 1 deletion hosting/Squidex.Hosting.Abstractions/SimpleTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public SimpleTimer(Func<CancellationToken, Task> action, TimeSpan interval, ILog
}
catch (Exception ex)
{
log?.LogWarning(ex, "Failed to execute timer.");
if (log != null)
{
LogMessages.FailedToExecuteTimer(log, ex);
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions messaging/Squidex.Messaging.EntityFramework/EFSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public async Task OnErrorAsync(TransportResult result,

if (result.Data is not string id)
{
log.LogWarning("Transport message has no MongoDb ID.");
LogMessages.TransportMessageHasNoMongoDbId(log);
return;
}

Expand All @@ -115,7 +115,7 @@ await context.Set<EFMessage>()
}
catch (Exception ex)
{
log.LogError(ex, "Failed to put the message back into the queue '{queue}'.", channelName);
LogMessages.FailedToPutMessageBackIntoQueue(log, ex, channelName);
}
}

Expand All @@ -129,7 +129,7 @@ public async Task OnSuccessAsync(TransportResult result,

if (result.Data is not string id)
{
log.LogWarning("Transport message has no MongoDb ID.");
LogMessages.TransportMessageHasNoMongoDbId(log);
return;
}

Expand All @@ -142,7 +142,7 @@ await context.Set<EFMessage>().Where(x => x.Id == id)
}
catch (Exception ex)
{
log.LogError(ex, "Failed to remove message from queue '{queue}'.", channelName);
LogMessages.FailedToRemoveMessageFromQueue(log, ex, channelName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ await context.Set<EFMessage>()

if (updated > 0)
{
log.LogInformation("{collectionName}: Items reset: {count}.", channelName, updated);
LogMessages.ItemsReset(log, channelName, updated);
}
}, updateInterval, log);

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

using Microsoft.Extensions.Logging;

namespace Squidex.Messaging.EntityFramework;

internal static partial class LogMessages
{
[LoggerMessage(EventId = 1, Level = LogLevel.Warning, Message = "Transport message has no database ID.")]
public static partial void TransportMessageHasNoMongoDbId(ILogger logger);

[LoggerMessage(EventId = 2, Level = LogLevel.Error, Message = "Failed to put the message back into the queue '{queue}'.")]
public static partial void FailedToPutMessageBackIntoQueue(ILogger logger, Exception exception, string queue);

[LoggerMessage(EventId = 3, Level = LogLevel.Error, Message = "Failed to remove message from queue '{queue}'.")]
public static partial void FailedToRemoveMessageFromQueue(ILogger logger, Exception exception, string queue);

[LoggerMessage(EventId = 4, Level = LogLevel.Information, Message = "{collectionName}: Items reset: {count}.")]
public static partial void ItemsReset(ILogger logger, string collectionName, int count);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private async Task SubscribeCoreAsync(MessageTransportCallback callback, ILogger
}
catch (Exception ex) when (ex is not OperationCanceledException)
{
log.LogError(ex, "Failed to consume message from subscription '{subscription}'.", subscriberClient.SubscriptionName.SubscriptionId);
LogMessages.FailedToConsumeMessageFromSubscription(log, ex, subscriberClient.SubscriptionName.SubscriptionId);
}
}

Expand Down
16 changes: 16 additions & 0 deletions messaging/Squidex.Messaging.GoogleCloud/LogMessages.cs
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.Messaging.GoogleCloud;

internal static partial class LogMessages
{
[LoggerMessage(EventId = 1, Level = LogLevel.Error, Message = "Failed to consume message from subscription '{subscription}'.")]
public static partial void FailedToConsumeMessageFromSubscription(ILogger logger, Exception exception, string subscription);
}
8 changes: 4 additions & 4 deletions messaging/Squidex.Messaging.Kafka/KafkaLogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,24 @@ public static Action<IProducer<TKey, TValue>, LogMessage> ProducerLog(ILogger lo

private static void Log(ILogger log, string stats)
{
log.LogInformation("Kafka stastics received: {stats}.", stats);
LogMessages.KafkaStatisticsReceived(log, stats);
}

private static void Log(ILogger log, Error error)
{
log.LogInformation("Kafka error with code {code} happened: {details}.", error.Code, error.Reason);
LogMessages.KafkaError(log, error.Code, error.Reason);
}

private static void Log(ILogger log, LogMessage message)
{
var level = GetLogLevel(message.Level);

if (log.IsEnabled(level))
if (!log.IsEnabled(level))
{
return;
}

log.Log(level, "Kafka log recieved from system {system}: {message}.", message.Name, message.Message);
LogMessages.KafkaLog(log, level, message.Name, message.Message);
}

private static LogLevel GetLogLevel(SyslogLevel level)
Expand Down
Loading
Loading