Compare commits
2 Commits
develop
...
feature/lo
| Author | SHA1 | Date | |
|---|---|---|---|
| 22ddf238ef | |||
| 7bf2994cda |
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 14
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 14.0.25123.0
|
VisualStudioVersion = 17.14.36109.1
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendNSWMessageService", "SendNSWMessageService\SendNSWMessageService.csproj", "{E6F8F110-77E7-4348-9875-CAD095BF8E24}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SendNSWMessageService", "SendNSWMessageService\SendNSWMessageService.csproj", "{E6F8F110-77E7-4348-9875-CAD095BF8E24}"
|
||||||
EndProject
|
EndProject
|
||||||
@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bsmd.hisnord", "bsmd.hisnor
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bsmd.status", "bsmd.status\bsmd.status.csproj", "{1EA7D5CE-4051-45CB-BE70-F8DD3DE0416A}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bsmd.status", "bsmd.status\bsmd.status.csproj", "{1EA7D5CE-4051-45CB-BE70-F8DD3DE0416A}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "bsmd.util", "bsmd.util\bsmd.util.csproj", "{5BA1BA6D-FB0E-4EC7-9AB2-47504E363C49}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -45,8 +47,15 @@ Global
|
|||||||
{1EA7D5CE-4051-45CB-BE70-F8DD3DE0416A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{1EA7D5CE-4051-45CB-BE70-F8DD3DE0416A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{1EA7D5CE-4051-45CB-BE70-F8DD3DE0416A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{1EA7D5CE-4051-45CB-BE70-F8DD3DE0416A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{1EA7D5CE-4051-45CB-BE70-F8DD3DE0416A}.Release|Any CPU.Build.0 = Release|Any CPU
|
{1EA7D5CE-4051-45CB-BE70-F8DD3DE0416A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{5BA1BA6D-FB0E-4EC7-9AB2-47504E363C49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{5BA1BA6D-FB0E-4EC7-9AB2-47504E363C49}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{5BA1BA6D-FB0E-4EC7-9AB2-47504E363C49}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{5BA1BA6D-FB0E-4EC7-9AB2-47504E363C49}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {C4D8D5B4-6702-49E1-A952-AF5335BE5186}
|
||||||
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
<root>
|
<root>
|
||||||
<level value="DEBUG"/>
|
<level value="DEBUG"/>
|
||||||
<appender-ref ref="LogFileAppender"/>
|
<appender-ref ref="LogFileAppender"/>
|
||||||
|
<appender-ref ref="LokiAppender" />
|
||||||
</root>
|
</root>
|
||||||
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
|
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
|
||||||
<param name="File" value="log-NSWMessageService.txt"/>
|
<param name="File" value="log-NSWMessageService.txt"/>
|
||||||
@ -22,6 +23,13 @@
|
|||||||
<param name="ConversionPattern" value="%date [%thread] %-5level [%logger] - %message%newline"/>
|
<param name="ConversionPattern" value="%date [%thread] %-5level [%logger] - %message%newline"/>
|
||||||
</layout>
|
</layout>
|
||||||
</appender>
|
</appender>
|
||||||
|
<appender name="LokiAppender" type="bsmd.util.LokiAppender, bsmd.util">
|
||||||
|
<LokiUrl value="https://loki.puls200.dyn-dns.org/loki/api/v1/push" />
|
||||||
|
<ApplicationName value="NSW service" />
|
||||||
|
<layout type="log4net.Layout.PatternLayout">
|
||||||
|
<conversionPattern value="[%date{yyyy-MM-dd HH:mm:ss}] %-5level - %message%newline" />
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
</log4net>
|
</log4net>
|
||||||
<startup>
|
<startup>
|
||||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||||
|
|||||||
@ -40,8 +40,8 @@
|
|||||||
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="log4net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=3.1.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\log4net.3.0.3\lib\net462\log4net.dll</HintPath>
|
<HintPath>..\packages\log4net.3.1.0\lib\net462\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
@ -126,6 +126,10 @@
|
|||||||
<Project>{1ea7d5ce-4051-45cb-be70-f8dd3de0416a}</Project>
|
<Project>{1ea7d5ce-4051-45cb-be70-f8dd3de0416a}</Project>
|
||||||
<Name>bsmd.status</Name>
|
<Name>bsmd.status</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\bsmd.util\bsmd.util.csproj">
|
||||||
|
<Project>{5ba1ba6d-fb0e-4ec7-9ab2-47504e363c49}</Project>
|
||||||
|
<Name>bsmd.util</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="log4net" version="3.0.3" targetFramework="net48" />
|
<package id="log4net" version="3.1.0" targetFramework="net48" />
|
||||||
</packages>
|
</packages>
|
||||||
@ -40,8 +40,8 @@
|
|||||||
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="log4net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=3.1.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\log4net.3.0.3\lib\net462\log4net.dll</HintPath>
|
<HintPath>..\packages\log4net.3.1.0\lib\net462\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
@ -52,8 +52,8 @@
|
|||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
<Reference Include="WinSCPnet, Version=1.15.0.15073, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf, processorArchitecture=MSIL">
|
<Reference Include="WinSCPnet, Version=1.16.0.16311, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\WinSCP.6.3.6\lib\net40\WinSCPnet.dll</HintPath>
|
<HintPath>..\packages\WinSCP.6.5.1\lib\net40\WinSCPnet.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -93,12 +93,12 @@
|
|||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="..\packages\WinSCP.6.3.6\build\WinSCP.targets" Condition="Exists('..\packages\WinSCP.6.3.6\build\WinSCP.targets')" />
|
<Import Project="..\packages\WinSCP.6.5.1\build\WinSCP.targets" Condition="Exists('..\packages\WinSCP.6.5.1\build\WinSCP.targets')" />
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Error Condition="!Exists('..\packages\WinSCP.6.3.6\build\WinSCP.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\WinSCP.6.3.6\build\WinSCP.targets'))" />
|
<Error Condition="!Exists('..\packages\WinSCP.6.5.1\build\WinSCP.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\WinSCP.6.5.1\build\WinSCP.targets'))" />
|
||||||
</Target>
|
</Target>
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
Other similar extension points exist, see Microsoft.Common.targets.
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="log4net" version="3.0.3" targetFramework="net48" />
|
<package id="log4net" version="3.1.0" targetFramework="net48" />
|
||||||
<package id="WinSCP" version="6.3.6" targetFramework="net48" />
|
<package id="WinSCP" version="6.5.1" targetFramework="net48" />
|
||||||
</packages>
|
</packages>
|
||||||
@ -89,8 +89,8 @@
|
|||||||
<UseWinFormsOutOfProcDesigner>False</UseWinFormsOutOfProcDesigner>
|
<UseWinFormsOutOfProcDesigner>False</UseWinFormsOutOfProcDesigner>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="log4net, Version=3.0.4.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=3.1.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\ENI2\packages\log4net.3.0.4\lib\net462\log4net.dll</HintPath>
|
<HintPath>..\packages\log4net.3.1.0\lib\net462\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
<HintPath>..\ENI2\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
<HintPath>..\ENI2\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="log4net" version="3.0.4" targetFramework="net48" />
|
<package id="log4net" version="3.1.0" targetFramework="net48" />
|
||||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
|
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
|
||||||
</packages>
|
</packages>
|
||||||
@ -38,8 +38,8 @@
|
|||||||
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="log4net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=3.1.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\log4net.3.0.3\lib\net462\log4net.dll</HintPath>
|
<HintPath>..\packages\log4net.3.1.0\lib\net462\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="log4net" version="3.0.3" targetFramework="net48" />
|
<package id="log4net" version="3.1.0" targetFramework="net48" />
|
||||||
</packages>
|
</packages>
|
||||||
@ -38,8 +38,8 @@
|
|||||||
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="log4net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=3.1.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\log4net.3.0.3\lib\net462\log4net.dll</HintPath>
|
<HintPath>..\packages\log4net.3.1.0\lib\net462\log4net.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="log4net" version="3.0.3" targetFramework="net48" />
|
<package id="log4net" version="3.1.0" targetFramework="net48" />
|
||||||
</packages>
|
</packages>
|
||||||
@ -38,8 +38,11 @@
|
|||||||
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>..\bsmdKey.snk</AssemblyOriginatorKeyFile>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="log4net, Version=3.0.3.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
<Reference Include="log4net, Version=3.1.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\log4net.3.0.3\lib\net462\log4net.dll</HintPath>
|
<HintPath>..\packages\log4net.3.1.0\lib\net462\log4net.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Configuration" />
|
<Reference Include="System.Configuration" />
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="log4net" version="3.0.3" targetFramework="net48" />
|
<package id="log4net" version="3.1.0" targetFramework="net48" />
|
||||||
|
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
|
||||||
</packages>
|
</packages>
|
||||||
155
bsmd.util/LokiAppender.cs
Normal file
155
bsmd.util/LokiAppender.cs
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
// Copyright (c) 2025 schick Informatik
|
||||||
|
// Description: Appender for Loki/Grafana remote logging
|
||||||
|
//
|
||||||
|
|
||||||
|
namespace bsmd.util
|
||||||
|
{
|
||||||
|
|
||||||
|
using log4net.Appender;
|
||||||
|
using log4net.Core;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
public class LokiAppender : AppenderSkeleton
|
||||||
|
{
|
||||||
|
|
||||||
|
#region Fields
|
||||||
|
|
||||||
|
private static readonly HttpClient _httpClient = new HttpClient();
|
||||||
|
|
||||||
|
private readonly ConcurrentQueue<Tuple<string, string>> _logQueue = new ConcurrentQueue<Tuple<string, string>>();
|
||||||
|
|
||||||
|
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
||||||
|
|
||||||
|
private bool _batchingStarted = false;
|
||||||
|
|
||||||
|
private readonly object _batchLock = new object();
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
|
||||||
|
public string LokiUrl { get; set; }
|
||||||
|
public string ApplicationName { get; set; } = "log4net-app";
|
||||||
|
|
||||||
|
public int BatchSize { get; set; } = 10;
|
||||||
|
|
||||||
|
public int BatchIntervalMs { get; set; } = 2000;
|
||||||
|
|
||||||
|
public int MaxRetries { get; set; } = 5;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region overrides
|
||||||
|
|
||||||
|
protected override void Append(LoggingEvent loggingEvent)
|
||||||
|
{
|
||||||
|
string timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + "000000";
|
||||||
|
string message = RenderLoggingEvent(loggingEvent);
|
||||||
|
|
||||||
|
_logQueue.Enqueue(new Tuple<string, string>(timestamp, message));
|
||||||
|
|
||||||
|
// Start background batch loop once
|
||||||
|
if (!_batchingStarted)
|
||||||
|
{
|
||||||
|
lock (_batchLock)
|
||||||
|
{
|
||||||
|
if (!_batchingStarted)
|
||||||
|
{
|
||||||
|
_ = Task.Run(() => BatchLoop(_cts.Token));
|
||||||
|
_batchingStarted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task BatchLoop(CancellationToken ct)
|
||||||
|
{
|
||||||
|
while (!ct.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Task.Delay(BatchIntervalMs, ct);
|
||||||
|
|
||||||
|
var batch = new List<Tuple<string, string>>();
|
||||||
|
while (batch.Count < BatchSize && _logQueue.TryDequeue(out var entry))
|
||||||
|
batch.Add(entry);
|
||||||
|
|
||||||
|
if (batch.Count == 0) continue;
|
||||||
|
|
||||||
|
var payload = new
|
||||||
|
{
|
||||||
|
streams = new[]
|
||||||
|
{
|
||||||
|
new
|
||||||
|
{
|
||||||
|
stream = new
|
||||||
|
{
|
||||||
|
app = ApplicationName,
|
||||||
|
level = "info" // Optional: capture log level from batch
|
||||||
|
},
|
||||||
|
values = batch.ConvertAll(e => new[] { e.Item1, e.Item2 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
string json = JsonConvert.SerializeObject(payload);
|
||||||
|
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
|
await SendWithRetry(content, MaxRetries, ct);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
// Graceful shutdown
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
ErrorHandler.Error("Error in Loki batch loop", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SendWithRetry(HttpContent content, int maxRetries, CancellationToken ct)
|
||||||
|
{
|
||||||
|
int attempt = 0;
|
||||||
|
TimeSpan delay = TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
|
while (attempt <= maxRetries && !ct.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await _httpClient.PostAsync(LokiUrl, content, ct);
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
|
return;
|
||||||
|
|
||||||
|
attempt++;
|
||||||
|
await Task.Delay(delay, ct);
|
||||||
|
delay = TimeSpan.FromSeconds(delay.TotalSeconds * 2); // exponential backoff
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
attempt++;
|
||||||
|
await Task.Delay(delay, ct);
|
||||||
|
delay = TimeSpan.FromSeconds(delay.TotalSeconds * 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorHandler.Error($"Failed to send logs to Loki after {attempt} retries.");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnClose()
|
||||||
|
{
|
||||||
|
_cts.Cancel();
|
||||||
|
base.OnClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
33
bsmd.util/Properties/AssemblyInfo.cs
Normal file
33
bsmd.util/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("bsmd.util")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("bsmd.util")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2025")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("5ba1ba6d-fb0e-4ec7-9ab2-47504e363c49")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
60
bsmd.util/bsmd.util.csproj
Normal file
60
bsmd.util/bsmd.util.csproj
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{5BA1BA6D-FB0E-4EC7-9AB2-47504E363C49}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>bsmd.util</RootNamespace>
|
||||||
|
<AssemblyName>bsmd.util</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<Deterministic>true</Deterministic>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="log4net, Version=3.1.0.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\log4net.3.1.0\lib\net462\log4net.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Configuration" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Web" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="LokiAppender.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="bsmd.util.licenseheader" />
|
||||||
|
<None Include="packages.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
||||||
5
bsmd.util/bsmd.util.licenseheader
Normal file
5
bsmd.util/bsmd.util.licenseheader
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
extensions: designer.cs generated.cs
|
||||||
|
extensions: .cs .cpp .h
|
||||||
|
// Copyright (c) 2025 schick Informatik
|
||||||
|
// Description:
|
||||||
|
//
|
||||||
5
bsmd.util/packages.config
Normal file
5
bsmd.util/packages.config
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="log4net" version="3.1.0" targetFramework="net48" />
|
||||||
|
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
|
||||||
|
</packages>
|
||||||
Loading…
Reference in New Issue
Block a user