using Serilog.Core;
using Serilog.Events;

namespace SlnMesnac.Serilog
{
    // 自定义日志级别缩写增强器
    public class CustomLogLevelAbbreviationEnricher : ILogEventEnricher
    {
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            string abbreviation;
            switch (logEvent.Level)
            {
                case LogEventLevel.Verbose:
                    abbreviation = "VRB";
                    break;

                case LogEventLevel.Debug:
                    abbreviation = "DBG";
                    break;

                case LogEventLevel.Information:
                    abbreviation = "INF";
                    break;

                case LogEventLevel.Warning:
                    abbreviation = "WRN";
                    break;

                case LogEventLevel.Error:
                    abbreviation = "ERR";
                    break;

                case LogEventLevel.Fatal:
                    abbreviation = "FTL";
                    break;

                case (LogEventLevel)35: // 自定义的 AgvLevel
                    abbreviation = "AGV";
                    break;

                default:
                    abbreviation = logEvent.Level.ToString();
                    break;
            }

            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("LevelAbbreviation", abbreviation));
        }
    }
}