Initial version

This commit is contained in:
2026-02-27 21:12:55 +01:00
parent d2bbbd8bc7
commit a73beb6ed5
184 changed files with 90370 additions and 63 deletions

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.Network" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="9.0.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,197 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
using Serilog.Formatting.Json;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
var builder = WebApplication.CreateBuilder(args);
//
// LOGGER CONFIGURATION (Equivalent to LoggerSettings)
//
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose()
.Enrich.WithProperty("Id", "TEST")
.Enrich.WithProperty("AppName", "[JIJ BENT EEN BRASSER!]")
.WriteTo.Async(a => a.Console())
.WriteTo.Async(a => a.File(
path: "logs/web-.log",
rollingInterval: RollingInterval.Day,
fileSizeLimitBytes: 1_000_000,
rollOnFileSizeLimit: true,
retainedFileCountLimit: 5,
shared: true))
.WriteTo.Async(a => a.File(
new JsonFormatter(),
path: "logs/test.json",
rollingInterval: RollingInterval.Day))
//.WriteTo.Seq("http://localhost:5341") // central logging
.CreateLogger();
builder.Services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(Path.Combine(Directory.GetCurrentDirectory(), "keys")))
.SetApplicationName("SerilogStressTest");
builder.Services.AddRazorPages();
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenAnyIP(6000);
});
var app = builder.Build();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
//
// ==============================
// 🔥 TESTS START HERE
// ==============================
//
_ = Task.Run(RunLoggingTestsAsync);
_ = Task.Run(RunWebLoggingTestsAsync);
_ = Task.Run(RunLoggingExceptionTests);
_ = Task.Run(RunWebLoggingExceptionTests);
//_ = Task.Run(RunMemoryLeakTest);
_ = Task.Run(RunTcpLoggerTest);
app.Run();
// =======================================================
// 1⃣ EXACT HIGH-SPEED FILE LOGGING LOOP
// =======================================================
async Task RunLoggingTestsAsync()
{
for (var i = 0; i < 9_000_000; i++)
{
Log.Information("test to file {i} INFO", i);
Log.Fatal("test to file {i} CRITICAL", i);
Log.Debug("test to file {i} DEBUG", i);
Log.Error("test to file {i} ERROR", i);
Log.Verbose("test to file {i} TRACE", i);
Log.Warning("test to file {i} WARNING", i);
Console.WriteLine($"Logged: {i}");
await Task.Delay(1);
}
}
// =======================================================
// 2⃣ WEB LOGGER STRESS TEST
// =======================================================
async Task RunWebLoggingTestsAsync()
{
int i = 0;
while (true)
{
i++;
Log.Information("web-test {i}", i);
Log.Debug("web-test {i}", i);
Log.Warning("web-test {i}", i);
Log.Error("web-test {i}", i);
Log.Verbose("web-test {i}", i);
await Task.Delay(1);
}
}
// =======================================================
// 3⃣ EXCEPTION TEST (FILE LOGGER)
// =======================================================
void RunLoggingExceptionTests()
{
for (int i = 0; i < 10; i++)
{
try
{
throw new Exception($"Normal Exception {i}");
}
catch (Exception ex)
{
Log.Error(ex, "Exception {Index}", i);
Console.WriteLine($"Normal ExceptionLogged: {i}");
}
}
}
// =======================================================
// 4⃣ WEB EXCEPTION TEST
// =======================================================
void RunWebLoggingExceptionTests()
{
for (int i = 0; i < 10; i++)
{
try
{
throw new Exception($"WebException {i}");
}
catch (Exception ex)
{
Log.Fatal(ex, "CRITICAL");
Log.Debug(ex, "DEBUG");
Log.Error(ex, "ERROR");
Log.Verbose(ex, "TRACE");
Log.Warning(ex, "WARNING");
Log.Information(ex, "INFORMATION");
Console.WriteLine($"WebExceptionLogged: {i}");
}
}
}
// =======================================================
// 6⃣ MEMORY LEAK TEST (IDENTICAL BEHAVIOR)
// =======================================================
async Task RunMemoryLeakTest()
{
var managedLeak = new List<byte[]>();
while (true)
{
managedLeak.Add(new byte[5_000_000]); // 5MB
Marshal.AllocHGlobal(10_000_000); // 10MB unmanaged
await Task.Delay(500);
}
}
// =======================================================
// 7⃣ TCP LOGGER TEST
// =======================================================
async Task RunTcpLoggerTest()
{
using var client = new TcpClient();
try
{
await client.ConnectAsync("192.168.1.1", 12345);
int i = 0;
while (true)
{
var message = Encoding.UTF8.GetBytes($"TCP log {++i}\n");
await client.GetStream().WriteAsync(message);
await Task.Delay(1000);
}
}
catch
{
Log.Warning("TCP server not reachable");
}
}

View File

@@ -0,0 +1,12 @@
{
"profiles": {
"EonaCat.LogStack.SerilogTest": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:56815;http://localhost:56816"
}
}
}

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<key id="ce36e671-3994-4686-93db-52c792888079" version="1">
<creationDate>2026-02-13T12:58:52.6395786Z</creationDate>
<activationDate>2026-02-13T12:58:52.6395786Z</activationDate>
<expirationDate>2026-05-14T12:58:52.6395786Z</expirationDate>
<descriptor deserializerType="Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
<descriptor>
<encryption algorithm="AES_256_CBC" />
<validation algorithm="HMACSHA256" />
<masterKey p4:requiresEncryption="true" xmlns:p4="http://schemas.asp.net/2015/03/dataProtection">
<!-- Warning: the key below is in an unencrypted form. -->
<value>/V8LCH65h4jnYN0CNj+b+f/KcWTcYS7HEFlmIS8h/ryyTH5YEXlxLIWHxoZYbu6+vY7JXF3O+iDkdNnuW8BtFg==</value>
</masterKey>
</descriptor>
</descriptor>
</key>