using EonaCat.LogStack.Core;
using System;
using System.Runtime.CompilerServices;

namespace EonaCat.LogStack.Boosters;

// 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.

/// <summary>
/// Adds application name and version to log events
/// </summary>
public sealed class ApplicationBooster : BoosterBase
{
    private readonly string _applicationName;
    private readonly string? _version;

    public ApplicationBooster(string applicationName, string? version = null) : base("Application")
    {
        _applicationName = applicationName ?? throw new ArgumentNullException(nameof(applicationName));
        _version = version;
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public override bool Boost(ref LogEventBuilder builder)
    {
        builder.WithProperty("Application", _applicationName);
        if (_version != null)
        {
            builder.WithProperty("Version", _version);
        }
        return true;
    }
}
