Removed Async code as we don't handle async ops anymore

This commit is contained in:
Zafer Balkan
2024-11-21 19:32:01 +02:00
parent b4d90fca2b
commit 3f67e7a050
7 changed files with 28 additions and 26 deletions

View File

@@ -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<LogEntry>(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)
{

View File

@@ -20,9 +20,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.Http" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.SyslogMessages" Version="4.0.0" />
</ItemGroup>
@@ -33,6 +34,9 @@
</ItemGroup>
<ItemGroup>
<Reference Include="Serilog.Sinks.SyslogMessages">
<HintPath>Serilog.Sinks.SyslogMessages.dll</HintPath>
</Reference>
<Reference Include="TechnitiumLibrary.Net">
<HintPath>..\..\..\TechnitiumLibrary\bin\TechnitiumLibrary.Net.dll</HintPath>
<Private>false</Private>

View File

@@ -52,11 +52,11 @@ namespace LogExporter.Strategy
return _exportStrategies.Count > 0;
}
public async Task ImplementStrategyForAsync(List<LogEntry> logs)
public void ImplementStrategy(List<LogEntry> logs)
{
foreach (var strategy in _exportStrategies.Values)
{
await strategy.ExportAsync(logs).ConfigureAwait(false);
strategy.Export(logs);
}
}

View File

@@ -19,8 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
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<LogEntry> logs)
public void Export(List<LogEntry> 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

View File

@@ -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<LogEntry> logs)
public void Export(List<LogEntry> 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

View File

@@ -28,6 +28,6 @@ namespace LogExporter.Strategy
/// </summary>
public interface IExportStrategy: IDisposable
{
Task ExportAsync(List<LogEntry> logs);
void Export(List<LogEntry> logs);
}
}

View File

@@ -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<LogEntry> logs)
public void Export(List<LogEntry> 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