Updated
This commit is contained in:
+33
-18
@@ -7,28 +7,43 @@ using EonaCat.LogStack.Core;
|
||||
var logger = new LogBuilder("MyApp")
|
||||
.WithMinimumLevel(LogLevel.Information)
|
||||
.WriteToConsole()
|
||||
.WriteToFile("C:\\tesss", maxFileSize: 50 * 1024 * 1024)
|
||||
//.WriteToJsonFile("./logs", maxFileSize: 50 * 1024 * 1024)
|
||||
//.WriteToHttp("https://127.0.0.1")
|
||||
//.WriteToUdp("127.0.0.1", 514)
|
||||
//.WriteToTcp("127.0.0.1", 514)
|
||||
//.WriteToDatabase(null)
|
||||
//.WriteToDiscord("https://discord.com/api/webhooks/...")
|
||||
//.WriteToMicrosoftTeams("https://outlook.office.com/webhook/...")
|
||||
//.WriteToElasticSearch("http://localhost:9200/logs")
|
||||
//.WriteToGraylogFlow(null)
|
||||
//.WriteToZabbixFlow(null)
|
||||
.WriteToFile("./testlogs", maxFileSize: 50 * 1024 * 1024)
|
||||
.BoostWithCorrelationId()
|
||||
.BoostWithProcessId()
|
||||
.Build();
|
||||
|
||||
Console.WriteLine("Logger created successfully");
|
||||
Console.WriteLine("Writing log entries...");
|
||||
|
||||
|
||||
while (true)
|
||||
// Test: Write a few log entries and then dispose
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
logger.Information("Application started");
|
||||
logger.Error(new Exception("Nerd!"), "Something went wrong");
|
||||
await Task.Delay(1);
|
||||
}
|
||||
logger.Information("Application started - iteration " + i);
|
||||
logger.Error(new Exception("Nerd!"), "Something went wrong - iteration " + i);
|
||||
}
|
||||
|
||||
await logger.DisposeAsync(); // Flushes all logs
|
||||
Console.WriteLine("Wrote 10 log entries");
|
||||
|
||||
// Wait a bit for the flush to happen
|
||||
await Task.Delay(3000);
|
||||
|
||||
Console.WriteLine("Disposing logger...");
|
||||
await logger.DisposeAsync(); // Flushes all logs
|
||||
|
||||
Console.WriteLine("Logging complete. Check ./testlogs for log files.");
|
||||
|
||||
// List files that were created
|
||||
var logdir = new System.IO.DirectoryInfo("./testlogs");
|
||||
if (logdir.Exists)
|
||||
{
|
||||
var files = logdir.GetFiles();
|
||||
Console.WriteLine($"Found {files.Length} log files:");
|
||||
foreach (var file in files)
|
||||
{
|
||||
Console.WriteLine($" - {file.Name} ({file.Length} bytes)");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("./testlogs directory does not exist!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user