From 3f67e7a050afd8a4d65b1a47053a9b3d89d298cc Mon Sep 17 00:00:00 2001 From: Zafer Balkan Date: Thu, 21 Nov 2024 19:32:01 +0200 Subject: [PATCH] Removed Async code as we don't handle async ops anymore --- Apps/LogExporterApp/App.cs | 11 +++++------ Apps/LogExporterApp/LogExporterApp.csproj | 6 +++++- Apps/LogExporterApp/Strategy/ExportManager.cs | 4 ++-- Apps/LogExporterApp/Strategy/FileExportStrategy.cs | 10 +++++----- Apps/LogExporterApp/Strategy/HttpExportStrategy.cs | 9 +++++---- Apps/LogExporterApp/Strategy/IExportStrategy.cs | 2 +- Apps/LogExporterApp/Strategy/SyslogExportStrategy.cs | 12 +++++------- 7 files changed, 28 insertions(+), 26 deletions(-) diff --git a/Apps/LogExporterApp/App.cs b/Apps/LogExporterApp/App.cs index 6220d29d..333c5b45 100644 --- a/Apps/LogExporterApp/App.cs +++ b/Apps/LogExporterApp/App.cs @@ -25,7 +25,6 @@ using System.Collections.Generic; using System.Net; using System.Threading; using System.Threading.Tasks; -using TechnitiumLibrary; using TechnitiumLibrary.Net.Dns; using TechnitiumLibrary.Net.Dns.ResourceRecords; @@ -82,7 +81,7 @@ namespace LogExporter { _queueTimer?.Dispose(); - ExportLogsAsync().Sync(); //flush any pending logs + ExportLogs(); //flush any pending logs _logBuffer.Dispose(); } @@ -138,7 +137,7 @@ namespace LogExporter #region private - private async Task ExportLogsAsync() + private void ExportLogs() { var logs = new List(BULK_INSERT_COUNT); @@ -151,15 +150,15 @@ namespace LogExporter // If we have any logs to process, export them if (logs.Count > 0) { - await _exportManager.ImplementStrategyForAsync(logs); + _exportManager.ImplementStrategy(logs); } } - private async void HandleExportLogCallback(object? state) + private void HandleExportLogCallback(object? state) { try { - await ExportLogsAsync().ConfigureAwait(false); + ExportLogs(); } catch (Exception ex) { diff --git a/Apps/LogExporterApp/LogExporterApp.csproj b/Apps/LogExporterApp/LogExporterApp.csproj index e6235eb4..87ffa0d9 100644 --- a/Apps/LogExporterApp/LogExporterApp.csproj +++ b/Apps/LogExporterApp/LogExporterApp.csproj @@ -20,9 +20,10 @@ - + + @@ -33,6 +34,9 @@ + + Serilog.Sinks.SyslogMessages.dll + ..\..\..\TechnitiumLibrary\bin\TechnitiumLibrary.Net.dll false diff --git a/Apps/LogExporterApp/Strategy/ExportManager.cs b/Apps/LogExporterApp/Strategy/ExportManager.cs index df70359f..f6e2d59c 100644 --- a/Apps/LogExporterApp/Strategy/ExportManager.cs +++ b/Apps/LogExporterApp/Strategy/ExportManager.cs @@ -52,11 +52,11 @@ namespace LogExporter.Strategy return _exportStrategies.Count > 0; } - public async Task ImplementStrategyForAsync(List logs) + public void ImplementStrategy(List logs) { foreach (var strategy in _exportStrategies.Values) { - await strategy.ExportAsync(logs).ConfigureAwait(false); + strategy.Export(logs); } } diff --git a/Apps/LogExporterApp/Strategy/FileExportStrategy.cs b/Apps/LogExporterApp/Strategy/FileExportStrategy.cs index cedb65f4..181bd1c8 100644 --- a/Apps/LogExporterApp/Strategy/FileExportStrategy.cs +++ b/Apps/LogExporterApp/Strategy/FileExportStrategy.cs @@ -19,8 +19,6 @@ along with this program. If not, see . using Serilog; using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace LogExporter.Strategy { @@ -45,10 +43,12 @@ namespace LogExporter.Strategy #region public - public Task ExportAsync(List logs) + public void Export(List logs) { - var tasks = logs.Select(log => Task.Run(() => _sender.Information(log.ToString()))); - return Task.WhenAll(tasks); + foreach (LogEntry logEntry in logs) + { + _sender.Information(logEntry.ToString()); + } } #endregion public diff --git a/Apps/LogExporterApp/Strategy/HttpExportStrategy.cs b/Apps/LogExporterApp/Strategy/HttpExportStrategy.cs index 8a5fb611..d2219018 100644 --- a/Apps/LogExporterApp/Strategy/HttpExportStrategy.cs +++ b/Apps/LogExporterApp/Strategy/HttpExportStrategy.cs @@ -23,7 +23,6 @@ using Serilog.Sinks.Http; using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -59,10 +58,12 @@ namespace LogExporter.Strategy #region public - public Task ExportAsync(List logs) + public void Export(List logs) { - var tasks = logs.Select(log => Task.Run(() => _sender.Information(log.ToString()))); - return Task.WhenAll(tasks); + foreach (LogEntry logEntry in logs) + { + _sender.Information(logEntry.ToString()); + } } #endregion public diff --git a/Apps/LogExporterApp/Strategy/IExportStrategy.cs b/Apps/LogExporterApp/Strategy/IExportStrategy.cs index 63feef3b..6c1647fa 100644 --- a/Apps/LogExporterApp/Strategy/IExportStrategy.cs +++ b/Apps/LogExporterApp/Strategy/IExportStrategy.cs @@ -28,6 +28,6 @@ namespace LogExporter.Strategy /// public interface IExportStrategy: IDisposable { - Task ExportAsync(List logs); + void Export(List logs); } } diff --git a/Apps/LogExporterApp/Strategy/SyslogExportStrategy.cs b/Apps/LogExporterApp/Strategy/SyslogExportStrategy.cs index eee2d356..dc4bf2af 100644 --- a/Apps/LogExporterApp/Strategy/SyslogExportStrategy.cs +++ b/Apps/LogExporterApp/Strategy/SyslogExportStrategy.cs @@ -24,7 +24,6 @@ using Serilog.Sinks.Syslog; using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; namespace LogExporter.Strategy { @@ -75,14 +74,13 @@ namespace LogExporter.Strategy #region public - public Task ExportAsync(List logs) + public void Export(List logs) { - var tasks = logs - .Select(log => Task.Run(() => - Log.Information(_formatter.FormatMessage(Convert(log)))) - ); - return Task.WhenAll(tasks); + foreach (var log in logs) + { + Log.Information(_formatter.FormatMessage(Convert(log))); + } } #endregion public