Merge branch 'feature/logger-refactoring' into feature/logger-Notify

This commit is contained in:
Anton Suhorukov 2022-05-16 14:22:29 +03:00
commit deb81c8549
10 changed files with 201 additions and 27 deletions

View File

@ -63,7 +63,7 @@ public class KafkaCacheNotify<T> : IDisposable, ICacheNotify<T> where T : IMessa
if (_producer == null)
{
_producer = new ProducerBuilder<AscCacheItem, T>(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<T> : IDisposable, ICacheNotify<T> where T : IMessa
}
catch (ProduceException<Null, string> 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<T> : IDisposable, ICacheNotify<T> where T : IMessa
if (_producer == null)
{
_producer = new ProducerBuilder<AscCacheItem, T>(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<T> : IDisposable, ICacheNotify<T> where T : IMessa
}
catch (ProduceException<Null, string> 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<T> : IDisposable, ICacheNotify<T> 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<T> : IDisposable, ICacheNotify<T> where T : IMessa
}
using var c = new ConsumerBuilder<AscCacheItem, T>(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<T> : IDisposable, ICacheNotify<T> where T : IMessa
}
catch (Exception e)
{
_logger.LogError(e, "Kafka onmessage");
_logger.ErrorKafkaOnmessage(e);
}
}
}
catch (ConsumeException e)
{
_logger.LogError(e, "Subscribe");
_logger.ErrorSubscribe(e);
}
}
}

View File

@ -70,7 +70,7 @@ public class RabbitMQCache<T> : IDisposable, ICacheNotify<T> where T : IMessage<
{
TryConnect();
_logger.LogTrace("Creating RabbitMQ consumer channel");
_logger.TraceCreatingRabbitMQ();
var channel = _connection.CreateModel();
@ -85,7 +85,7 @@ public class RabbitMQCache<T> : IDisposable, ICacheNotify<T> 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<T> : IDisposable, ICacheNotify<T> where T : IMessage<
private void StartBasicConsume()
{
_logger.LogTrace("Starting RabbitMQ basic consume");
_logger.TraceStartingRabbitMQ();
if (_consumerChannel != null)
{
@ -111,7 +111,7 @@ public class RabbitMQCache<T> : IDisposable, ICacheNotify<T> where T : IMessage<
}
else
{
_logger.LogError("StartBasicConsume can't call on _consumerChannel == null");
_logger.ErrorStartBasicConsumeCanNotCall();
}
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
};
}

View File

@ -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<string, string>();
_logger.LogError(error, "InitTranslations");
_logger.ErrorInitTranslations(error);
}
}