using EonaCat.LogStack.Configuration;
using EonaCat.LogStack.Core;

// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.

var logger = new LogBuilder("MyApp")
    .WithMinimumLevel(LogLevel.Information)
    .WriteToConsole()
    .WriteToFile("./testlogs", maxFileSize: 50 * 1024 * 1024)
    .BoostWithCorrelationId()
    .BoostWithProcessId()
    .Build();

Console.WriteLine("Logger created successfully");
Console.WriteLine("Writing log entries...");

// Test: Write a few log entries and then dispose
for (int i = 0; i < 10; i++)
{
    logger.Information("Application started - iteration " + i);
    logger.Error(new Exception("Nerd!"), "Something went wrong - iteration " + i);
}

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!");
}
