Merge pull request #660 from ONLYOFFICE/feature/logger-Webhooks.Service

Feature/logger webhooks.service
This commit is contained in:
Pavel Bannov 2022-05-19 13:17:06 +03:00 committed by GitHub
commit 01558a28e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 6 deletions

View File

@ -33,10 +33,12 @@ global using ASC.Api.Core;
global using ASC.Api.Core.Extensions;
global using ASC.Common;
global using ASC.Common.Caching;
global using ASC.Common.Log;
global using ASC.Common.Utils;
global using ASC.Web.Webhooks;
global using ASC.Webhooks.Core;
global using ASC.Webhooks.Service.Services;
global using ASC.Webhooks.Service.Log;
global using ASC.Webhooks.Service.Services;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.Extensions.Hosting.WindowsServices;

View File

@ -0,0 +1,32 @@
// (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.Webhooks.Service.Log;
internal static partial class WebhookSenderLogger
{
[LoggerMessage(Level = LogLevel.Debug, Message = "Procedure: Finish.")]
public static partial void DebugProcedureFinish(this ILogger logger);
}

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.Webhooks.Service.Log;
internal static partial class WorkerServiceLogger
{
[LoggerMessage(Level = LogLevel.Trace, Message = "Procedure: Waiting for data. Sleep {waitingPeriod}.")]
public static partial void TraceProcedure(this ILogger logger, TimeSpan waitingPeriod);
[LoggerMessage(Level = LogLevel.Debug, Message = "Response: {response}")]
public static partial void DebugResponse(this ILogger logger, HttpResponseMessage response);
}

View File

@ -55,7 +55,7 @@ public class WorkerService : BackgroundService
if (queueSize == 0) // change to "<= threadCount"
{
_logger.LogTrace("Procedure: Waiting for data. Sleep {waitingPeriod}.", _waitingPeriod);
_logger.TraceProcedure(_waitingPeriod);
await Task.Delay(_waitingPeriod, stoppingToken);
@ -89,7 +89,7 @@ public class WorkerService : BackgroundService
}
Task.WaitAll(tasks.ToArray());
_logger.LogDebug("Procedure: Finish.");
_logger.DebugProcedureFinish();
}
}
}

View File

@ -75,13 +75,13 @@ public class WebhookSender
if (response.IsSuccessStatusCode)
{
UpdateDb(dbWorker, id, response, request, ProcessStatus.Success);
_log.LogDebug("Response: {response}", response);
_log.DebugResponse(response);
break;
}
else if (i == RepeatCount - 1)
{
UpdateDb(dbWorker, id, response, request, ProcessStatus.Failed);
_log.LogDebug("Response: {response}", response);
_log.DebugResponse(response);
}
}
catch (Exception ex)
@ -91,7 +91,7 @@ public class WebhookSender
UpdateDb(dbWorker, id, response, request, ProcessStatus.Failed);
}
_log.LogError(ex.Message);
_log.ErrorWithException(ex);
continue;
}
}