This commit is contained in:
2026-02-13 15:46:30 +01:00
parent 85d42c0641
commit e13f7217ab
16 changed files with 759 additions and 1170 deletions

View File

@@ -7,8 +7,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EonaCat.MemoryGuard" Version="1.1.1" />
<PackageReference Include="EonaCat.MemoryGuard.Generator" Version="1.1.0" />
<PackageReference Include="EonaCat.Versioning" Version="1.2.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@@ -6,7 +6,7 @@
using EonaCat.Logger.EonaCatCoreLogger.Models;
using EonaCat.Logger.LogClient;
using EonaCat.Logger.Managers;
using EonaCat.MemoryGuard;
//using EonaCat.MemoryGuard;
using EonaCat.Versioning.Helpers;
using EonaCat.Web.RateLimiter;
using EonaCat.Web.RateLimiter.Endpoints.Extensions;
@@ -42,22 +42,22 @@
});
Console.ReadKey();
var _config = new MemoryGuardConfiguration
{
MonitoringInterval = TimeSpan.FromSeconds(5),
AnalysisInterval = TimeSpan.FromSeconds(10),
PredictionInterval = TimeSpan.FromSeconds(15),
LeakDetectionThreshold = TimeSpan.FromSeconds(5),
SuspiciousObjectThreshold = TimeSpan.FromSeconds(3),
BackgroundReportingInterval = TimeSpan.FromMinutes(1.5),
CaptureStackTraces = true,
EnableAutoRemediation = true,
AutoSaveReports = true,
MemoryPressureThreshold = 500 * 1024 * 1024, // 500MB
BackgroundAnalysisInterval = TimeSpan.FromMinutes(1),
OptimizationInterval = TimeSpan.FromMinutes(10),
PatternDetectionInterval = TimeSpan.FromMinutes(3)
};
//var _config = new MemoryGuardConfiguration
//{
// MonitoringInterval = TimeSpan.FromSeconds(5),
// AnalysisInterval = TimeSpan.FromSeconds(10),
// PredictionInterval = TimeSpan.FromSeconds(15),
// LeakDetectionThreshold = TimeSpan.FromSeconds(5),
// SuspiciousObjectThreshold = TimeSpan.FromSeconds(3),
// BackgroundReportingInterval = TimeSpan.FromMinutes(1.5),
// CaptureStackTraces = true,
// EnableAutoRemediation = true,
// AutoSaveReports = true,
// MemoryPressureThreshold = 500 * 1024 * 1024, // 500MB
// BackgroundAnalysisInterval = TimeSpan.FromMinutes(1),
// OptimizationInterval = TimeSpan.FromMinutes(10),
// PatternDetectionInterval = TimeSpan.FromMinutes(3)
//};
//MemoryGuard.Start(_config);
@@ -112,7 +112,6 @@
logger.LoggerSettings.LogTrace();
logger.LoggerSettings.LogTraffic();
logger.LoggerSettings.OnLog += LoggerSettings_OnLog;
logger.LoggerSettings.UseMask = true;
//LoggerSettings.CustomHeaderFormatter = ctx =>
//{
@@ -168,7 +167,6 @@
options.MaxRolloverFiles = 5;
//options.FileSizeLimit = 1 * 1024 * 1024 / 4;
options.UseLocalTime = true;
options.UseMask = true;
builder.Logging.AddEonaCatFileLogger(fileLoggerOptions: options, filenamePrefix: "web");
builder.Logging.AddEonaCatConsoleLogger();
@@ -287,23 +285,22 @@
}
//MemoryLeakTester.Start(logger);
_ = Task.Run(RunMemoryReportTask).ConfigureAwait(false);
_ = Task.Run(RunMaskTest).ConfigureAwait(false);
//_ = Task.Run(RunMemoryReportTask).ConfigureAwait(false);
_ = Task.Run(RunWebLoggerTestsAsync).ConfigureAwait(false);
_ = Task.Run(RunWebLoggingTests).ConfigureAwait(false);
_ = Task.Run(RunLoggingTestsAsync).ConfigureAwait(false);
_ = Task.Run(RunLoggingExceptionTests).ConfigureAwait(false);
_ = Task.Run(RunWebLoggingExceptionTests).ConfigureAwait(false);
async Task RunMemoryReportTask()
{
while (true)
{
await MemoryGuard.PrintReportAsync().ConfigureAwait(false);
await Task.Delay(60000).ConfigureAwait(false);
Console.ReadKey();
}
}
//async Task RunMemoryReportTask()
//{
// while (true)
// {
// await MemoryGuard.PrintReportAsync().ConfigureAwait(false);
// await Task.Delay(60000).ConfigureAwait(false);
// Console.ReadKey();
// }
//}
void RunWebLoggingExceptionTests()
{
@@ -347,29 +344,6 @@
}
}
async Task RunMaskTest()
{
if (!Directory.Exists(logger.LogFolder))
{
Directory.CreateDirectory(logger.LogFolder);
}
for (var i = 0; i < 9000000; i++)
{
var message = $"mask-test {i}";
app.Logger.LogInformation("password: test");
app.Logger.LogInformation("JWT Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c");
app.Logger.LogInformation("JWT Token2: eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.iOeNU4dAFFeBwNj6qdhdvm-IvDQrTa6R22lQVJVuWJxorJfeQww5Nwsra0PjaOYhAMj9jNMO5YLmud8U7iQ5gJK2zYyepeSuXhfSi8yjFZfRiSkelqSkU19I-Ja8aQBDbqXf2SAWA8mHF8VS3F08rgEaLCyv98fLLH4vSvsJGf6ueZSLKDVXz24rZRXGWtYYk_OYYTVgR1cg0BLCsuCvqZvHleImJKiWmtS0-CymMO4MMjCy_FIl6I56NqLE9C87tUVpo1mT-kbg5cHDD8I7MjCW5Iii5dethB4Vid3mZ6emKjVYgXrtkOQ-JyGMh6fnQxEFN1ft33GX2eRHluK9eg");
using (var file = new StreamWriter(Path.Combine(logger.LogFolder, "testmask.log"), true))
{
await file.WriteAsync(message);
}
Console.WriteLine($"Masked: {i}");
await Task.Delay(1);
}
}
async Task RunLoggingTestsAsync()
{
var loggerSettings = new LoggerSettings();
@@ -430,10 +404,10 @@
app.Run();
}
private static void Instance_LeakDetected(object? sender, EonaCat.MemoryGuard.EventArguments.MemoryLeakDetectedEventArgs e)
{
// Leak detected
}
//private static void Instance_LeakDetected(object? sender, EonaCat.MemoryGuard.EventArguments.MemoryLeakDetectedEventArgs e)
//{
// // Leak detected
//}
}
static class MemoryLeakTester