updated packages and flush batchlogger after dispose, short lived logging works

alphons <alphons@heijden.com> 13 May 2026, 15:49
315b8c735f604769d4c2de57005dbcefb37d1764
9 files changed
  • src/VanDerHeijden.Logging.File/VanDerHeijden.Logging.File.csproj
  • src/VanDerHeijden.Logging.MongoDb/VanDerHeijden.Logging.MongoDb.csproj
  • src/VanDerHeijden.Logging.Redis/VanDerHeijden.Logging.Redis.csproj
  • src/VanDerHeijden.Logging.Sql/VanDerHeijden.Logging.Sql.csproj
  • src/VanDerHeijden.Logging/BatchedLogger.cs
  • src/VanDerHeijden.Logging/VanDerHeijden.Logging.csproj
  • tests/VanDerHeijden.Logging.File.AppConsole/Program.cs
  • tests/VanDerHeijden.Logging.File.AppConsole/VanDerHeijden.Logging.File.AppConsole.csproj
  • tests/VanDerHeijden.Logging.File.AppConsole/appsettings.json
diff --git a/src/VanDerHeijden.Logging.File/VanDerHeijden.Logging.File.csproj b/src/VanDerHeijden.Logging.File/VanDerHeijden.Logging.File.csproj
index c66bb40..abbbceb 100644
--- a/src/VanDerHeijden.Logging.File/VanDerHeijden.Logging.File.csproj
+++ b/src/VanDerHeijden.Logging.File/VanDerHeijden.Logging.File.csproj
@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<PackageId>VanDerHeijden.Logging.File</PackageId>
- <Version>10.0.7</Version>
+ <Version>10.0.8</Version>
<Authors>VanDerHeijden</Authors>
<Description>File log writer for VanDerHeijden.Logging: writes batched log entries to daily rotating text files.</Description>
<PackageTags>logging;file;batched</PackageTags>
diff --git a/src/VanDerHeijden.Logging.MongoDb/VanDerHeijden.Logging.MongoDb.csproj b/src/VanDerHeijden.Logging.MongoDb/VanDerHeijden.Logging.MongoDb.csproj
index 148be44..f8d579f 100644
--- a/src/VanDerHeijden.Logging.MongoDb/VanDerHeijden.Logging.MongoDb.csproj
+++ b/src/VanDerHeijden.Logging.MongoDb/VanDerHeijden.Logging.MongoDb.csproj
@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<PackageId>VanDerHeijden.Logging.MongoDb</PackageId>
- <Version>10.0.8</Version>
+ <Version>10.0.9</Version>
<Authors>VanDerHeijden</Authors>
<Description>MongoDB log writer for VanDerHeijden.Logging: writes batched log entries to a MongoDB collection.</Description>
<PackageTags>logging;mongodb;batched</PackageTags>
diff --git a/src/VanDerHeijden.Logging.Redis/VanDerHeijden.Logging.Redis.csproj b/src/VanDerHeijden.Logging.Redis/VanDerHeijden.Logging.Redis.csproj
index 7d28b7d..c7bff27 100644
--- a/src/VanDerHeijden.Logging.Redis/VanDerHeijden.Logging.Redis.csproj
+++ b/src/VanDerHeijden.Logging.Redis/VanDerHeijden.Logging.Redis.csproj
@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<PackageId>VanDerHeijden.Logging.Redis</PackageId>
- <Version>10.0.7</Version>
+ <Version>10.0.8</Version>
<Authors>VanDerHeijden</Authors>
<Description>Redis log writer for VanDerHeijden.Logging: writes batched log entries to a Redis list using RPUSH.</Description>
<PackageTags>logging;redis;batched</PackageTags>
diff --git a/src/VanDerHeijden.Logging.Sql/VanDerHeijden.Logging.Sql.csproj b/src/VanDerHeijden.Logging.Sql/VanDerHeijden.Logging.Sql.csproj
index 2fb82ac..1c0cf7e 100644
--- a/src/VanDerHeijden.Logging.Sql/VanDerHeijden.Logging.Sql.csproj
+++ b/src/VanDerHeijden.Logging.Sql/VanDerHeijden.Logging.Sql.csproj
@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<PackageId>VanDerHeijden.Logging.Sql</PackageId>
- <Version>10.0.7</Version>
+ <Version>10.0.8</Version>
<Authors>VanDerHeijden</Authors>
<Description>SQL Server log writer for VanDerHeijden.Logging: writes batched log entries to a SQL Server table using SqlBulkCopy.</Description>
<PackageTags>logging;sql;sqlserver;batched</PackageTags>
diff --git a/src/VanDerHeijden.Logging/BatchedLogger.cs b/src/VanDerHeijden.Logging/BatchedLogger.cs
index 50bef7d..8bfb9a7 100644
--- a/src/VanDerHeijden.Logging/BatchedLogger.cs
+++ b/src/VanDerHeijden.Logging/BatchedLogger.cs
@@ -115,11 +115,11 @@ public sealed class BatchedLogger<T> : IDisposable
}
}
}
- catch (OperationCanceledException)
+ catch (Exception) when (batch.Count > 0)
{
- if (batch.Count > 0)
- try { await ExecuteWriteAsync(batch, CancellationToken.None); } catch { }
+ try { await ExecuteWriteAsync(batch, CancellationToken.None); } catch { }
}
+ catch { }
}
private async Task ExecuteWriteAsync(List<T> batch, CancellationToken ct)
diff --git a/src/VanDerHeijden.Logging/VanDerHeijden.Logging.csproj b/src/VanDerHeijden.Logging/VanDerHeijden.Logging.csproj
index 47ae1d1..19ce3ea 100644
--- a/src/VanDerHeijden.Logging/VanDerHeijden.Logging.csproj
+++ b/src/VanDerHeijden.Logging/VanDerHeijden.Logging.csproj
@@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<PackageId>VanDerHeijden.Logging</PackageId>
- <Version>10.0.7</Version>
+ <Version>10.0.8</Version>
<Authors>VanDerHeijden</Authors>
<Description>Core batched logging abstractions for .NET: IBatchedLogWriter&lt;T&gt;, BatchedLogger&lt;T&gt; and BatchedLoggerProvider&lt;T&gt;.</Description>
<PackageTags>logging;batched;core</PackageTags>
diff --git a/tests/VanDerHeijden.Logging.File.AppConsole/Program.cs b/tests/VanDerHeijden.Logging.File.AppConsole/Program.cs
index 1bc52a6..a6c360e 100644
--- a/tests/VanDerHeijden.Logging.File.AppConsole/Program.cs
+++ b/tests/VanDerHeijden.Logging.File.AppConsole/Program.cs
@@ -1 +1,25 @@
-Console.WriteLine("Hello, World!");
+
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Logging;
+using VanDerHeijden.Logging;
+using VanDerHeijden.Logging.File;
+
+string APPSETTINGS_FILE = "appsettings.json";
+
+IConfigurationRoot configuration = new ConfigurationBuilder()
+ .SetBasePath(Directory.GetCurrentDirectory())
+ .AddJsonFile(APPSETTINGS_FILE, optional: false, reloadOnChange: true)
+ .Build();
+
+IConfigurationSection configurationSection = configuration.GetSection("CustomLogging");
+using var loggerFactory = LoggerFactory.Create(b =>
+{
+ if (configurationSection.GetValue<bool>("ConsoleLogging"))
+ b.AddCustomLogger();
+ if (configurationSection.GetValue<bool>("FileLogging"))
+ b.AddFileLogger();
+});
+
+var logger = loggerFactory.CreateLogger<string>();
+
+logger.LogInformation("Fast logging");
\ No newline at end of file
diff --git a/tests/VanDerHeijden.Logging.File.AppConsole/VanDerHeijden.Logging.File.AppConsole.csproj b/tests/VanDerHeijden.Logging.File.AppConsole/VanDerHeijden.Logging.File.AppConsole.csproj
index ed9781c..012629f 100644
--- a/tests/VanDerHeijden.Logging.File.AppConsole/VanDerHeijden.Logging.File.AppConsole.csproj
+++ b/tests/VanDerHeijden.Logging.File.AppConsole/VanDerHeijden.Logging.File.AppConsole.csproj
@@ -1,10 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <TargetFramework>net10.0</TargetFramework>
- <ImplicitUsings>enable</ImplicitUsings>
- <Nullable>enable</Nullable>
- </PropertyGroup>
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net10.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="10.0.2" />
+ <PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.8" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\src\VanDerHeijden.Logging.File\VanDerHeijden.Logging.File.csproj" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <None Update="appsettings.json">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
+ </ItemGroup>
</Project>
diff --git a/tests/VanDerHeijden.Logging.File.AppConsole/appsettings.json b/tests/VanDerHeijden.Logging.File.AppConsole/appsettings.json
new file mode 100644
index 0000000..d6c2c88
--- /dev/null
+++ b/tests/VanDerHeijden.Logging.File.AppConsole/appsettings.json
@@ -0,0 +1,11 @@
+{
+ "CustomLogging": {
+ "ConsoleLogging": true,
+ "FileLogging": true
+ },
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information"
+ }
+ }
+}
\ No newline at end of file