using EonaCat.Logger.Extensions;
using EonaCat.Logger.Managers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Logging.AddEonaCatFileLogger();
builder.Services.AddRazorPages();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapRazorPages();

Task.Run(RunLoggingTests);

Task.Run(RunWebLoggingTests);

void RunWebLoggingTests()
{
    for (int i = 0; i < 1000000; i++)
    {
        app.Logger.LogInformation($"web-test {i}");
        Console.WriteLine($"WebLogged: {i}");
        Task.Delay(1);
    }
}

void RunLoggingTests()
{
    var loggerSettings = new LoggerSettings();
    loggerSettings.FileLoggerOptions.BackgroundQueueSize = 100;
    var logger = new LogManager(loggerSettings);

    for (int i = 0; i < 1000000; i++)
    {
        logger.Write($"test {i}");
        Console.WriteLine($"Logged: {i}");
        Task.Delay(1);
    }
}

app.Run();
