diff --git a/common/ASC.Common/Caching/KafkaCacheNotify.cs b/common/ASC.Common/Caching/KafkaCacheNotify.cs index 9b3b2f22bd..a63e191df4 100644 --- a/common/ASC.Common/Caching/KafkaCacheNotify.cs +++ b/common/ASC.Common/Caching/KafkaCacheNotify.cs @@ -63,7 +63,7 @@ public class KafkaCacheNotify : IDisposable, ICacheNotify where T : IMessa if (_producer == null) { _producer = new ProducerBuilder(new ProducerConfig(_clientConfig)) - .SetErrorHandler((_, e) => _logger.LogError(e.ToString())) + .SetErrorHandler((_, e) => _logger.Error(e.ToString())) .SetKeySerializer(_keySerializer) .SetValueSerializer(_valueSerializer) .Build(); @@ -89,11 +89,11 @@ public class KafkaCacheNotify : IDisposable, ICacheNotify where T : IMessa } catch (ProduceException e) { - _logger.LogError(e, "KafkaCacheNotify Publish"); + _logger.ErrorKafkaCacheNotifyPublish(e); } catch (Exception e) { - _logger.LogError(e, "KafkaCacheNotify Publish"); + _logger.ErrorKafkaCacheNotifyPublish(e); } } @@ -104,7 +104,7 @@ public class KafkaCacheNotify : IDisposable, ICacheNotify where T : IMessa if (_producer == null) { _producer = new ProducerBuilder(new ProducerConfig(_clientConfig)) - .SetErrorHandler((_, e) => _logger.LogError(e.ToString())) + .SetErrorHandler((_, e) => _logger.Error(e.ToString())) .SetKeySerializer(_keySerializer) .SetValueSerializer(_valueSerializer) .Build(); @@ -130,11 +130,11 @@ public class KafkaCacheNotify : IDisposable, ICacheNotify where T : IMessa } catch (ProduceException e) { - _logger.LogError(e, "KafkaCacheNotify PublishAsync"); + _logger.ErrorKafkaCacheNotifyPublishAsync(e); } catch (Exception e) { - _logger.LogError(e, "KafkaCacheNotify PublishAsync"); + _logger.ErrorKafkaCacheNotifyPublishAsync(e); } } @@ -154,7 +154,7 @@ public class KafkaCacheNotify : IDisposable, ICacheNotify where T : IMessa using (var adminClient = new AdminClientBuilder(_adminClientConfig) - .SetErrorHandler((_, e) => _logger.LogError(e.ToString())) + .SetErrorHandler((_, e) => _logger.Error(e.ToString())) .Build()) { try @@ -175,7 +175,7 @@ public class KafkaCacheNotify : IDisposable, ICacheNotify where T : IMessa } using var c = new ConsumerBuilder(conf) - .SetErrorHandler((_, e) => _logger.LogError(e.ToString())) + .SetErrorHandler((_, e) => _logger.Error(e.ToString())) .SetKeyDeserializer(_keyDeserializer) .SetValueDeserializer(_valueDeserializer) .Build(); @@ -197,13 +197,13 @@ public class KafkaCacheNotify : IDisposable, ICacheNotify where T : IMessa } catch (Exception e) { - _logger.LogError(e, "Kafka onmessage"); + _logger.ErrorKafkaOnmessage(e); } } } catch (ConsumeException e) { - _logger.LogError(e, "Subscribe"); + _logger.ErrorSubscribe(e); } } } diff --git a/common/ASC.Common/Caching/RabbitMQCache.cs b/common/ASC.Common/Caching/RabbitMQCache.cs index b9597f3a3a..e3e85ec46a 100644 --- a/common/ASC.Common/Caching/RabbitMQCache.cs +++ b/common/ASC.Common/Caching/RabbitMQCache.cs @@ -70,7 +70,7 @@ public class RabbitMQCache : IDisposable, ICacheNotify where T : IMessage< { TryConnect(); - _logger.LogTrace("Creating RabbitMQ consumer channel"); + _logger.TraceCreatingRabbitMQ(); var channel = _connection.CreateModel(); @@ -85,7 +85,7 @@ public class RabbitMQCache : IDisposable, ICacheNotify where T : IMessage< channel.CallbackException += (sender, ea) => { - _logger.LogWarning(ea.Exception, "Recreating RabbitMQ consumer channel"); + _logger.WarningRecreatingRabbitMQ(ea.Exception); _consumerChannel.Dispose(); _consumerChannel = CreateConsumerChannel(); @@ -99,7 +99,7 @@ public class RabbitMQCache : IDisposable, ICacheNotify where T : IMessage< private void StartBasicConsume() { - _logger.LogTrace("Starting RabbitMQ basic consume"); + _logger.TraceStartingRabbitMQ(); if (_consumerChannel != null) { @@ -111,7 +111,7 @@ public class RabbitMQCache : IDisposable, ICacheNotify where T : IMessage< } else { - _logger.LogError("StartBasicConsume can't call on _consumerChannel == null"); + _logger.ErrorStartBasicConsumeCanNotCall(); } } diff --git a/common/ASC.Common/GlobalUsings.cs b/common/ASC.Common/GlobalUsings.cs index 9f4c2ce202..b388c14506 100644 --- a/common/ASC.Common/GlobalUsings.cs +++ b/common/ASC.Common/GlobalUsings.cs @@ -29,7 +29,7 @@ global using System.Collections.Concurrent; global using System.Configuration; global using System.Diagnostics; global using System.Globalization; -global using System.Net; +global using System.Net; global using System.Net.Mail; global using System.Reflection; global using System.Runtime.Caching; @@ -51,6 +51,7 @@ global using ARSoft.Tools.Net.Dns; global using ASC.Common; global using ASC.Common.Caching; global using ASC.Common.DependencyInjection; +global using ASC.Common.Log; global using ASC.Common.Mapping.PrimitiveTypeConverters; global using ASC.Common.Security; global using ASC.Common.Security.Authorizing; diff --git a/common/ASC.Common/Log/CommonLogger.cs b/common/ASC.Common/Log/CommonLogger.cs index de6849e804..fb5899238e 100644 --- a/common/ASC.Common/Log/CommonLogger.cs +++ b/common/ASC.Common/Log/CommonLogger.cs @@ -30,9 +30,18 @@ public static partial class CommonLogger [LoggerMessage(Level = LogLevel.Error)] public static partial void ErrorWithException(this ILogger logger, Exception exception); + [LoggerMessage(Level = LogLevel.Error)] + public static partial void Error(this ILogger logger, string message); + [LoggerMessage(Level = LogLevel.Debug)] public static partial void Debug(this ILogger logger, string message); [LoggerMessage(Level = LogLevel.Information)] public static partial void Information(this ILogger logger, string message); + + [LoggerMessage(Level = LogLevel.Warning)] + public static partial void Warning(this ILogger logger, string message); + + [LoggerMessage(Level = LogLevel.Warning)] + public static partial void WarningWithException(this ILogger logger, Exception exception); } diff --git a/common/ASC.Common/Log/DistributedTaskQueueLogger.cs b/common/ASC.Common/Log/DistributedTaskQueueLogger.cs new file mode 100644 index 0000000000..ac3cd70df4 --- /dev/null +++ b/common/ASC.Common/Log/DistributedTaskQueueLogger.cs @@ -0,0 +1,35 @@ +// (c) Copyright Ascensio System SIA 2010-2022 +// +// This program is a free software product. +// You can redistribute it and/or modify it under the terms +// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software +// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended +// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of +// any third-party rights. +// +// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see +// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html +// +// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. +// +// The interactive user interfaces in modified source and object code versions of the Program must +// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. +// +// Pursuant to Section 7(b) of the License you must retain the original Product logo when +// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under +// trademark law for use of our trademarks. +// +// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing +// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 +// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + +namespace ASC.Common.Log; +internal static partial class DistributedTaskQueueLogger +{ + [LoggerMessage(Level = LogLevel.Trace, Message = "EnqueueTask '{distributedTaskId}' by instanse id '{instanceId}'")] + public static partial void TraceEnqueueTask(this ILogger logger, string DistributedTaskId, int instanceId); + + [LoggerMessage(Level = LogLevel.Trace, Message = "Publication DistributedTask '{DistributedTaskId}' by instanse id '{InstanceId}' ")] + public static partial void TracePublicationDistributedTask(this ILogger logger, string DistributedTaskId, int instanceId); +} diff --git a/common/ASC.Common/Log/KafkaCacheNotifyLogger.cs b/common/ASC.Common/Log/KafkaCacheNotifyLogger.cs new file mode 100644 index 0000000000..bd54900acd --- /dev/null +++ b/common/ASC.Common/Log/KafkaCacheNotifyLogger.cs @@ -0,0 +1,41 @@ +// (c) Copyright Ascensio System SIA 2010-2022 +// +// This program is a free software product. +// You can redistribute it and/or modify it under the terms +// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software +// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended +// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of +// any third-party rights. +// +// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see +// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html +// +// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. +// +// The interactive user interfaces in modified source and object code versions of the Program must +// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. +// +// Pursuant to Section 7(b) of the License you must retain the original Product logo when +// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under +// trademark law for use of our trademarks. +// +// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing +// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 +// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + +namespace ASC.Common.Log; +internal static partial class KafkaCacheNotifyLogger +{ + [LoggerMessage(Level = LogLevel.Error, Message = "KafkaCacheNotify Publish")] + public static partial void ErrorKafkaCacheNotifyPublish(this ILogger logger, Exception exception); + + [LoggerMessage(Level = LogLevel.Error, Message = "KafkaCacheNotify PublishAsync")] + public static partial void ErrorKafkaCacheNotifyPublishAsync(this ILogger logger, Exception exception); + + [LoggerMessage(Level = LogLevel.Error, Message = "Kafka onmessage")] + public static partial void ErrorKafkaOnmessage(this ILogger logger, Exception exception); + + [LoggerMessage(Level = LogLevel.Error, Message = "Subscribe")] + public static partial void ErrorSubscribe(this ILogger logger, Exception exception); +} diff --git a/common/ASC.Common/Log/RabbitMQCacheLogger.cs b/common/ASC.Common/Log/RabbitMQCacheLogger.cs new file mode 100644 index 0000000000..429b7e93cb --- /dev/null +++ b/common/ASC.Common/Log/RabbitMQCacheLogger.cs @@ -0,0 +1,41 @@ +// (c) Copyright Ascensio System SIA 2010-2022 +// +// This program is a free software product. +// You can redistribute it and/or modify it under the terms +// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software +// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended +// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of +// any third-party rights. +// +// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see +// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html +// +// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. +// +// The interactive user interfaces in modified source and object code versions of the Program must +// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. +// +// Pursuant to Section 7(b) of the License you must retain the original Product logo when +// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under +// trademark law for use of our trademarks. +// +// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing +// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 +// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + +namespace ASC.Common.Log; +internal static partial class RabbitMQCacheLogger +{ + [LoggerMessage(Level = LogLevel.Trace, Message = "Creating RabbitMQ consumer channel")] + public static partial void TraceCreatingRabbitMQ(this ILogger logger); + + [LoggerMessage(Level = LogLevel.Trace, Message = "Starting RabbitMQ basic consume")] + public static partial void TraceStartingRabbitMQ(this ILogger logger); + + [LoggerMessage(Level = LogLevel.Warning, Message = "Recreating RabbitMQ consumer channel")] + public static partial void WarningRecreatingRabbitMQ(this ILogger logger, Exception exception); + + [LoggerMessage(Level = LogLevel.Error, Message = "StartBasicConsume can't call on _consumerChannel == null")] + public static partial void ErrorStartBasicConsumeCanNotCall(this ILogger logger); +} diff --git a/common/ASC.Common/Log/TimeZoneConverterLogger.cs b/common/ASC.Common/Log/TimeZoneConverterLogger.cs new file mode 100644 index 0000000000..75e00d3a8b --- /dev/null +++ b/common/ASC.Common/Log/TimeZoneConverterLogger.cs @@ -0,0 +1,47 @@ +// (c) Copyright Ascensio System SIA 2010-2022 +// +// This program is a free software product. +// You can redistribute it and/or modify it under the terms +// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software +// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended +// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of +// any third-party rights. +// +// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see +// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html +// +// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. +// +// The interactive user interfaces in modified source and object code versions of the Program must +// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. +// +// Pursuant to Section 7(b) of the License you must retain the original Product logo when +// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under +// trademark law for use of our trademarks. +// +// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing +// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 +// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + +namespace ASC.Common.Log; +internal static partial class TimeZoneConverterLogger +{ + [LoggerMessage(Level = LogLevel.Information, Message = "TimeZone {timeZoneId} not found")] + public static partial void InformationTimeZoneNotFound(this ILogger logger, string timeZoneId); + + [LoggerMessage(Level = LogLevel.Error, Message = "OlsonTimeZone {olsonTimeZoneId} not found")] + public static partial void ErrorOlsonTimeZoneNotFound(this ILogger logger, string olsonTimeZoneId); + + [LoggerMessage(Level = LogLevel.Error, Message = "WindowsTimeZone {windowsTimeZoneId} not found")] + public static partial void ErrorWindowsTimeZoneNotFound(this ILogger logger, string windowsTimeZoneId); + + [LoggerMessage(Level = LogLevel.Error, Message = "GetTimeZone")] + public static partial void ErrorGetTimeZone(this ILogger logger, Exception exception); + + [LoggerMessage(Level = LogLevel.Error, Message = "InitMapZones")] + public static partial void ErrorInitMapZones(this ILogger logger, Exception exception); + + [LoggerMessage(Level = LogLevel.Error, Message = "InitTranslations")] + public static partial void ErrorInitTranslations(this ILogger logger, Exception exception); +} diff --git a/common/ASC.Common/Threading/DistributedTaskQueue.cs b/common/ASC.Common/Threading/DistributedTaskQueue.cs index 56253b35b1..d90ed55292 100644 --- a/common/ASC.Common/Threading/DistributedTaskQueue.cs +++ b/common/ASC.Common/Threading/DistributedTaskQueue.cs @@ -47,7 +47,7 @@ * in every copy of the program you distribute. * Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks. * -*/ +*/ namespace ASC.Common.Threading; @@ -154,7 +154,7 @@ public class DistributedTaskQueue task.Start(Scheduler); - _logger.LogTrace("EnqueueTask '{DistributedTaskId}' by instanse id '{InstanceId}'", distributedTask.Id, INSTANCE_ID); + _logger.TraceEnqueueTask(distributedTask.Id, INSTANCE_ID); } @@ -191,7 +191,7 @@ public class DistributedTaskQueue task.Start(Scheduler); - _logger.LogTrace("EnqueueTask '{DistributedTaskId}' by instanse id '{InstanceId}'", distributedTask.Id, INSTANCE_ID); + _logger.TraceEnqueueTask(distributedTask.Id, INSTANCE_ID); } @@ -256,7 +256,7 @@ public class DistributedTaskQueue SaveToCache(queueTasks); } - _logger.LogTrace("DequeueTask '{DistributedTaskId}' by instanse id '{InstanceId}'", id, INSTANCE_ID); + _logger.TraceEnqueueTask(id, INSTANCE_ID); } @@ -298,7 +298,7 @@ public class DistributedTaskQueue SaveToCache(queueTasks); - _logger.LogTrace("Publication DistributedTask '{DistributedTaskId}' by instanse id '{InstanceId}' ", task.Id, task.InstanceId); + _logger.TracePublicationDistributedTask(task.Id, task.InstanceId); }; } diff --git a/common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs b/common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs index eb3f9fb4b4..9c86af0079 100644 --- a/common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs +++ b/common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs @@ -82,7 +82,7 @@ public class TimeZoneConverter return mapZone.WindowsTimeZoneId; } - _logger.LogError($"OlsonTimeZone {olsonTimeZoneId} not found"); + _logger.ErrorOlsonTimeZoneNotFound(olsonTimeZoneId); return defaultIfNoMatch ? "UTC" : null; } @@ -103,7 +103,7 @@ public class TimeZoneConverter return mapZone.OlsonTimeZoneId; } - _logger.LogError($"WindowsTimeZone {windowsTimeZoneId} not found"); + _logger.ErrorWindowsTimeZoneNotFound(windowsTimeZoneId); return defaultIfNoMatch ? "Etc/GMT" : null; } @@ -137,20 +137,20 @@ public class TimeZoneConverter return TimeZoneInfo.FindSystemTimeZoneById(mapZone.OlsonTimeZoneId); } - _logger.LogInformation("TimeZone {timeZoneId} not found", timeZoneId); + _logger.InformationTimeZoneNotFound(timeZoneId); return defaultIfNoMatch ? GetTimeZoneByOffset(timeZoneId) ?? defaultTimezone : null; } catch (Exception error) { - _logger.LogError(error, "GetTimeZone"); + _logger.ErrorGetTimeZone(error); return defaultIfNoMatch ? defaultTimezone : null; } } catch (Exception error) { - _logger.LogError(error, "GetTimeZone"); + _logger.ErrorGetTimeZone(error); return defaultIfNoMatch ? defaultTimezone : null; } @@ -225,7 +225,7 @@ public class TimeZoneConverter catch (Exception error) { _mapZones = new MapZone[0]; - _logger.LogError(error, "InitMapZones"); + _logger.ErrorInitMapZones(error); } } @@ -325,7 +325,7 @@ public class TimeZoneConverter catch (Exception error) { _translations = new Dictionary(); - _logger.LogError(error, "InitTranslations"); + _logger.ErrorInitTranslations(error); } }