Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Serilog Pack v0.5.2
BepInEx/core/Serilog-Pack/Serilog.Sinks.BepInEx.dll
Decompiled a year agousing System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx.Logging; using Microsoft.CodeAnalysis; using Serilog.Configuration; using Serilog.Core; using Serilog.Data; using Serilog.Events; using Serilog.Formatting.Json; using Serilog.Parsing; using Serilog.Sinks.BepInEx; using Serilog.Sinks.BepInEx.Extensions; using Serilog.Sinks.BepInEx.Formatting; using Serilog.Sinks.BepInEx.Output; using Serilog.Sinks.BepInEx.Rendering; using Serilog.Sinks.BepInEx.Themes; using Sigurd.AvaloniaBepInExConsole.Common; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Sigurd Team")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("This package provides a Serilog sink that redirects events to the BepInEx Logger via an `ILogSource.`")] [assembly: AssemblyFileVersion("0.5.2.0")] [assembly: AssemblyInformationalVersion("0.5.2+023d3e475513d4fcad7c1235831a6573719b05c1")] [assembly: AssemblyProduct("Serilog.Sinks.BepInEx")] [assembly: AssemblyTitle("Serilog.Sinks.BepInEx")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/lc-sigurd/serilog-sinks-bepinex")] [assembly: InternalsVisibleTo("Serilog.Sinks.BepInEx.Tests")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace System.Runtime.Versioning { [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class RequiresPreviewFeaturesAttribute : Attribute { public string? Message { get; } public string? Url { get; set; } public RequiresPreviewFeaturesAttribute() { } public RequiresPreviewFeaturesAttribute(string? message) { Message = message; } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class CallerArgumentExpressionAttribute : Attribute { public string ParameterName { get; } public CallerArgumentExpressionAttribute(string parameterName) { ParameterName = parameterName; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class CollectionBuilderAttribute : Attribute { public Type BuilderType { get; } public string MethodName { get; } public CollectionBuilderAttribute(Type builderType, string methodName) { BuilderType = builderType; MethodName = methodName; } } [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class CompilerFeatureRequiredAttribute : Attribute { public const string RefStructs = "RefStructs"; public const string RequiredMembers = "RequiredMembers"; public string FeatureName { get; } public bool IsOptional { get; set; } public CompilerFeatureRequiredAttribute(string featureName) { FeatureName = featureName; } } [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class InterpolatedStringHandlerArgumentAttribute : Attribute { public string[] Arguments { get; } public InterpolatedStringHandlerArgumentAttribute(string argument) { Arguments = new string[1] { argument }; } public InterpolatedStringHandlerArgumentAttribute(params string[] arguments) { Arguments = arguments; } } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class InterpolatedStringHandlerAttribute : Attribute { } [EditorBrowsable(EditorBrowsableState.Never)] [ExcludeFromCodeCoverage] internal static class IsExternalInit { } [AttributeUsage(AttributeTargets.Method, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class ModuleInitializerAttribute : Attribute { } [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class RequiredMemberAttribute : Attribute { } [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] [EditorBrowsable(EditorBrowsableState.Never)] [ExcludeFromCodeCoverage] internal sealed class RequiresLocationAttribute : Attribute { } [AttributeUsage(AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Interface, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class SkipLocalsInitAttribute : Attribute { } } namespace System.Diagnostics.CodeAnalysis { [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class ExperimentalAttribute : Attribute { public string DiagnosticId { get; } public string? UrlFormat { get; set; } public ExperimentalAttribute(string diagnosticId) { DiagnosticId = diagnosticId; } } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] [ExcludeFromCodeCoverage] internal sealed class MemberNotNullAttribute : Attribute { public string[] Members { get; } public MemberNotNullAttribute(string member) { Members = new string[1] { member }; } public MemberNotNullAttribute(params string[] members) { Members = members; } } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)] [ExcludeFromCodeCoverage] internal sealed class MemberNotNullWhenAttribute : Attribute { public bool ReturnValue { get; } public string[] Members { get; } public MemberNotNullWhenAttribute(bool returnValue, string member) { ReturnValue = returnValue; Members = new string[1] { member }; } public MemberNotNullWhenAttribute(bool returnValue, params string[] members) { ReturnValue = returnValue; Members = members; } } [AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class SetsRequiredMembersAttribute : Attribute { } [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class StringSyntaxAttribute : Attribute { public const string CompositeFormat = "CompositeFormat"; public const string DateOnlyFormat = "DateOnlyFormat"; public const string DateTimeFormat = "DateTimeFormat"; public const string EnumFormat = "EnumFormat"; public const string GuidFormat = "GuidFormat"; public const string Json = "Json"; public const string NumericFormat = "NumericFormat"; public const string Regex = "Regex"; public const string TimeOnlyFormat = "TimeOnlyFormat"; public const string TimeSpanFormat = "TimeSpanFormat"; public const string Uri = "Uri"; public const string Xml = "Xml"; public string Syntax { get; } public object?[] Arguments { get; } public StringSyntaxAttribute(string syntax) { Syntax = syntax; Arguments = new object[0]; } public StringSyntaxAttribute(string syntax, params object?[] arguments) { Syntax = syntax; Arguments = arguments; } } [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)] [ExcludeFromCodeCoverage] internal sealed class UnscopedRefAttribute : Attribute { } } namespace Serilog { public static class BepInExLoggerConfigurationExtensions { private const string DefaultBepInExConsoleOutputTemplate = "[{Timestamp:HH:mm:ss}] [{SourceName}/{Level:u3}] {Message:lj}{NewLine}{Exception}"; public static LoggerConfiguration BepInExLogger(this LoggerSinkConfiguration sinkConfiguration, string logSourceName, string outputTemplate = "[{Timestamp:HH:mm:ss}] [{SourceName}/{Level:u3}] {Message:lj}{NewLine}{Exception}", IFormatProvider? formatProvider = null, BepInExConsoleTheme? theme = null) { if (sinkConfiguration == null) { throw new ArgumentNullException("sinkConfiguration"); } if (logSourceName == null) { throw new ArgumentNullException("logSourceName"); } if (theme == null) { theme = AnsiBepInExConsoleTheme.Literate; } SerilogLogSource logSource = new SerilogLogSource(logSourceName); return sinkConfiguration.Sink((ILogEventSink)(object)new BepInExLogSink(logSource, theme, outputTemplate, formatProvider), (LogEventLevel)0, (LoggingLevelSwitch)null); } } } namespace Serilog.Sinks.BepInEx { public record BepInExLogContext { public required LogLevel Level { get; init; } public required string SourceName { get; init; } public static BepInExLogContext FromLogEvent(LogEvent logEvent, string sourceName) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) LogEvent logEvent2 = logEvent; LogLevel level = logEvent2.Level.ToBepInExLevel(); return new BepInExLogContext { Level = level, SourceName = sourceName }; } [CompilerGenerated] protected virtual bool PrintMembers(StringBuilder builder) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) RuntimeHelpers.EnsureSufficientExecutionStack(); builder.Append("Level = "); LogLevel level = Level; builder.Append(((object)(LogLevel)(ref level)).ToString()); builder.Append(", SourceName = "); builder.Append((object?)SourceName); return true; } [CompilerGenerated] [SetsRequiredMembers] protected BepInExLogContext(BepInExLogContext original) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) Level = original.Level; SourceName = original.SourceName; } public BepInExLogContext() { } } public class BepInExLogSink : ILogEventSink, IDisposable { private const int DefaultWriteBufferCapacity = 256; private readonly IBepInExTextFormatter _plainFormatter; private readonly IBepInExTextFormatter _formatter; private readonly BepInExConsoleTheme _theme; private readonly SerilogLogSource _logSource; public BepInExLogSink(SerilogLogSource logSource, BepInExConsoleTheme theme, string outputTemplate, IFormatProvider? formatProvider) { _logSource = logSource ?? throw new ArgumentNullException("logSource"); _theme = theme ?? throw new ArgumentNullException("theme"); if (outputTemplate == null) { throw new ArgumentNullException("outputTemplate"); } _plainFormatter = new OutputTemplateRenderer(BepInExConsoleTheme.None, outputTemplate, formatProvider); _formatter = new OutputTemplateRenderer(theme, outputTemplate, formatProvider); Logger.Sources.Add((ILogSource)(object)_logSource); } public void Emit(LogEvent logEvent) { //IL_0086: Unknown result type (might be due to invalid IL or missing references) if (!_theme.CanBuffer) { throw new NotSupportedException("BepInEx log themes must support buffering."); } BepInExLogContext bepInExLogContext = BepInExLogContext.FromLogEvent(logEvent, _logSource.SourceName); StringWriter stringWriter = new StringWriter(new StringBuilder(256)); _plainFormatter.Format(logEvent, bepInExLogContext, stringWriter); string plainMessage = stringWriter.ToString().TrimEnd(); StringWriter stringWriter2 = new StringWriter(new StringBuilder(256)); _formatter.Format(logEvent, bepInExLogContext, stringWriter2); string ansiFormattedMessage = stringWriter2.ToString().TrimEnd(); _logSource.Log(bepInExLogContext.Level, plainMessage, ansiFormattedMessage); } public void Dispose() { Logger.Sources.Remove((ILogSource)(object)_logSource); _logSource.Dispose(); } } public static class ExceptionRenderStyleFlagsExtensions { public static bool Has(this ExceptionRenderStyleFlags @this, ExceptionRenderStyleFlags flags) { return (@this & flags) == flags; } } [Flags] public enum ExceptionRenderStyleFlags { Default = 0, IncludeInner = 1, IncludeStackTrace = 2, IncludeType = 4 } public class SerilogLogEventArgs : LogEventArgs, IAnsiFormattable { private readonly string _formattedData; public SerilogLogEventArgs(string data, string formattedData, LogLevel level, ILogSource source) : base((object)data, level, source) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) _formattedData = formattedData; } public override string ToString() { return $"{((LogEventArgs)this).Data}"; } public string ToAnsiFormattedString() { return _formattedData; } } public class SerilogLogSource : ILogSource, IDisposable { public string SourceName { get; } public event EventHandler<LogEventArgs>? LogEvent; public SerilogLogSource(string sourceName) { SourceName = sourceName; } static SerilogLogSource() { string assemblyName = "com.sigurd.avalonia_bepinex_console.common"; AssemblyName avaloniaBepinexConsoleCommonAssemblyName = new AssemblyName(assemblyName); Lazy<Assembly> assemblyHolder = new Lazy<Assembly>(delegate { AssemblyBuilder assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(avaloniaBepinexConsoleCommonAssemblyName, AssemblyBuilderAccess.Run); assemblyBuilder.DefineDynamicModule(avaloniaBepinexConsoleCommonAssemblyName.Name).DefineType("Sigurd.AvaloniaBepInExConsole.Common.IAnsiFormattable", TypeAttributes.Public | TypeAttributes.ClassSemanticsMask | TypeAttributes.Abstract).CreateType(); return assemblyBuilder; }); AppDomain.CurrentDomain.AssemblyResolve += (object _, ResolveEventArgs args) => (new AssemblyName(args.Name).Name != avaloniaBepinexConsoleCommonAssemblyName.Name) ? null : assemblyHolder.Value; } public void Dispose() { } public void Log(LogLevel level, string plainMessage, string ansiFormattedMessage) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) this.LogEvent?.Invoke(this, (LogEventArgs)(object)new SerilogLogEventArgs(plainMessage, ansiFormattedMessage, level, (ILogSource)(object)this)); } } } namespace Serilog.Sinks.BepInEx.Themes { public class AnsiBepInExConsoleTheme : BepInExConsoleTheme { private readonly IReadOnlyDictionary<BepInExConsoleThemeStyle, string> _styles; public static AnsiBepInExConsoleTheme Code { get; } = AnsiBepInExConsoleThemes.Code; public static AnsiBepInExConsoleTheme Grayscale { get; } = AnsiBepInExConsoleThemes.Grayscale; public static AnsiBepInExConsoleTheme Literate { get; } = AnsiBepInExConsoleThemes.Literate; public static AnsiBepInExConsoleTheme Sixteen { get; } = AnsiBepInExConsoleThemes.Sixteen; public override bool CanBuffer => true; public AnsiBepInExConsoleTheme(IReadOnlyDictionary<BepInExConsoleThemeStyle, string> styles) { if (styles == null) { throw new ArgumentNullException("styles"); } _styles = styles.ToDictionary<KeyValuePair<BepInExConsoleThemeStyle, string>, BepInExConsoleThemeStyle, string>((KeyValuePair<BepInExConsoleThemeStyle, string> kv) => kv.Key, (KeyValuePair<BepInExConsoleThemeStyle, string> kv) => kv.Value); } protected virtual string GetReset(BepInExLogContext context) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return context.Level.GetLevelAnsiReset(); } protected override int GetResetCharCount(BepInExLogContext context) { return GetReset(context).Length; } public override int Set(BepInExLogContext context, TextWriter output, BepInExConsoleThemeStyle style) { if (_styles.TryGetValue(style, out string value)) { output.Write(value); return value.Length; } return 0; } public override void Reset(BepInExLogContext context, TextWriter output) { output.Write(GetReset(context)); } } internal static class AnsiBepInExConsoleThemes { public static AnsiBepInExConsoleTheme Literate { get; } = new AnsiBepInExConsoleTheme(new Dictionary<BepInExConsoleThemeStyle, string> { [BepInExConsoleThemeStyle.Text] = "\u001b[38;5;0015m", [BepInExConsoleThemeStyle.SecondaryText] = "\u001b[38;5;0007m", [BepInExConsoleThemeStyle.TertiaryText] = "\u001b[38;5;0008m", [BepInExConsoleThemeStyle.SuccessText] = "\u001b[38;5;0113m", [BepInExConsoleThemeStyle.DangerText] = "\u001b[38;5;0208m", [BepInExConsoleThemeStyle.WarningText] = "\u001b[38;5;0011m", [BepInExConsoleThemeStyle.ExceptionText] = "\u001b[38;5;0009m", [BepInExConsoleThemeStyle.Invalid] = "\u001b[38;5;0011m", [BepInExConsoleThemeStyle.Null] = "\u001b[38;5;0027m", [BepInExConsoleThemeStyle.Name] = "\u001b[38;5;0007m", [BepInExConsoleThemeStyle.String] = "\u001b[38;5;0045m", [BepInExConsoleThemeStyle.Number] = "\u001b[38;5;0200m", [BepInExConsoleThemeStyle.Boolean] = "\u001b[38;5;0027m", [BepInExConsoleThemeStyle.Scalar] = "\u001b[38;5;0085m", [BepInExConsoleThemeStyle.LevelVerbose] = "\u001b[38;5;0007m", [BepInExConsoleThemeStyle.LevelDebug] = "\u001b[38;5;0007m", [BepInExConsoleThemeStyle.LevelInformation] = "\u001b[38;5;0015m", [BepInExConsoleThemeStyle.LevelWarning] = "\u001b[38;5;0011m", [BepInExConsoleThemeStyle.LevelError] = "\u001b[38;5;0015m\u001b[48;5;0196m", [BepInExConsoleThemeStyle.LevelFatal] = "\u001b[38;5;0015m\u001b[48;5;0196m" }); public static AnsiBepInExConsoleTheme Grayscale { get; } = new AnsiBepInExConsoleTheme(new Dictionary<BepInExConsoleThemeStyle, string> { [BepInExConsoleThemeStyle.Text] = "\u001b[37;1m", [BepInExConsoleThemeStyle.SecondaryText] = "\u001b[37m", [BepInExConsoleThemeStyle.TertiaryText] = "\u001b[30;1m", [BepInExConsoleThemeStyle.Invalid] = "\u001b[37;1m\u001b[47m", [BepInExConsoleThemeStyle.Null] = "\u001b[1m\u001b[37;1m", [BepInExConsoleThemeStyle.Name] = "\u001b[37m", [BepInExConsoleThemeStyle.String] = "\u001b[1m\u001b[37;1m", [BepInExConsoleThemeStyle.Number] = "\u001b[1m\u001b[37;1m", [BepInExConsoleThemeStyle.Boolean] = "\u001b[1m\u001b[37;1m", [BepInExConsoleThemeStyle.Scalar] = "\u001b[1m\u001b[37;1m", [BepInExConsoleThemeStyle.LevelVerbose] = "\u001b[30;1m", [BepInExConsoleThemeStyle.LevelDebug] = "\u001b[30;1m", [BepInExConsoleThemeStyle.LevelInformation] = "\u001b[37;1m", [BepInExConsoleThemeStyle.LevelWarning] = "\u001b[37;1m\u001b[47m", [BepInExConsoleThemeStyle.LevelError] = "\u001b[30m\u001b[47m", [BepInExConsoleThemeStyle.LevelFatal] = "\u001b[30m\u001b[47m" }); public static AnsiBepInExConsoleTheme Code { get; } = new AnsiBepInExConsoleTheme(new Dictionary<BepInExConsoleThemeStyle, string> { [BepInExConsoleThemeStyle.Text] = "\u001b[38;5;0253m", [BepInExConsoleThemeStyle.SecondaryText] = "\u001b[38;5;0246m", [BepInExConsoleThemeStyle.TertiaryText] = "\u001b[38;5;0242m", [BepInExConsoleThemeStyle.SuccessText] = "\u001b[38;5;0113m", [BepInExConsoleThemeStyle.DangerText] = "\u001b[38;5;0208m", [BepInExConsoleThemeStyle.WarningText] = "\u001b[38;5;0011m", [BepInExConsoleThemeStyle.ExceptionText] = "\u001b[38;5;0009m", [BepInExConsoleThemeStyle.Invalid] = "\u001b[33;1m", [BepInExConsoleThemeStyle.Null] = "\u001b[38;5;0038m", [BepInExConsoleThemeStyle.Name] = "\u001b[38;5;0081m", [BepInExConsoleThemeStyle.String] = "\u001b[38;5;0216m", [BepInExConsoleThemeStyle.Number] = "\u001b[38;5;151m", [BepInExConsoleThemeStyle.Boolean] = "\u001b[38;5;0038m", [BepInExConsoleThemeStyle.Scalar] = "\u001b[38;5;0079m", [BepInExConsoleThemeStyle.LevelVerbose] = "\u001b[37m", [BepInExConsoleThemeStyle.LevelDebug] = "\u001b[37m", [BepInExConsoleThemeStyle.LevelInformation] = "\u001b[37;1m", [BepInExConsoleThemeStyle.LevelWarning] = "\u001b[38;5;0229m", [BepInExConsoleThemeStyle.LevelError] = "\u001b[38;5;0197m\u001b[48;5;0238m", [BepInExConsoleThemeStyle.LevelFatal] = "\u001b[38;5;0197m\u001b[48;5;0238m" }); public static AnsiBepInExConsoleTheme Sixteen { get; } = new AnsiBepInExConsoleTheme(new Dictionary<BepInExConsoleThemeStyle, string> { [BepInExConsoleThemeStyle.Text] = "", [BepInExConsoleThemeStyle.SecondaryText] = "", [BepInExConsoleThemeStyle.TertiaryText] = "", [BepInExConsoleThemeStyle.SuccessText] = "\u001b[92m", [BepInExConsoleThemeStyle.DangerText] = "\u001b[31m", [BepInExConsoleThemeStyle.WarningText] = "\u001b[93m", [BepInExConsoleThemeStyle.ExceptionText] = "\u001b[91m", [BepInExConsoleThemeStyle.Invalid] = "\u001b[33m", [BepInExConsoleThemeStyle.Null] = "\u001b[34m", [BepInExConsoleThemeStyle.Name] = "", [BepInExConsoleThemeStyle.String] = "\u001b[36m", [BepInExConsoleThemeStyle.Number] = "\u001b[35m", [BepInExConsoleThemeStyle.Boolean] = "\u001b[34m", [BepInExConsoleThemeStyle.Scalar] = "\u001b[32m", [BepInExConsoleThemeStyle.LevelVerbose] = "", [BepInExConsoleThemeStyle.LevelDebug] = "\u001b[1m", [BepInExConsoleThemeStyle.LevelInformation] = "\u001b[96m", [BepInExConsoleThemeStyle.LevelWarning] = "\u001b[93m", [BepInExConsoleThemeStyle.LevelError] = "\u001b[91m", [BepInExConsoleThemeStyle.LevelFatal] = "\u001b[91m" }); } internal static class AnsiEscapeSequence { public const string Unthemed = ""; public const string Reset = "\u001b[0m"; public const string Bold = "\u001b[1m"; public const string Black = "\u001b[30m"; public const string Red = "\u001b[31m"; public const string Green = "\u001b[32m"; public const string Yellow = "\u001b[33m"; public const string Blue = "\u001b[34m"; public const string Magenta = "\u001b[35m"; public const string Cyan = "\u001b[36m"; public const string White = "\u001b[37m"; public const string BrightBlack = "\u001b[90m"; public const string BrightRed = "\u001b[91m"; public const string BrightGreen = "\u001b[92m"; public const string BrightYellow = "\u001b[93m"; public const string BrightBlue = "\u001b[94m"; public const string BrightMagenta = "\u001b[95m"; public const string BrightCyan = "\u001b[96m"; public const string BrightWhite = "\u001b[97m"; } public abstract class BepInExConsoleTheme { public static BepInExConsoleTheme None { get; } = new EmptyBepInExConsoleTheme(); public abstract bool CanBuffer { get; } public abstract int Set(BepInExLogContext context, TextWriter output, BepInExConsoleThemeStyle style); public abstract void Reset(BepInExLogContext context, TextWriter output); protected abstract int GetResetCharCount(BepInExLogContext context); internal BepInExStyleReset Apply(BepInExLogContext context, TextWriter output, BepInExConsoleThemeStyle style, ref int invisibleCharacterCount) { invisibleCharacterCount += Set(context, output, style); invisibleCharacterCount += GetResetCharCount(context); return new BepInExStyleReset(this, context, output); } } public enum BepInExConsoleThemeStyle { Text, BepInExText, SecondaryText, TertiaryText, SuccessText, DangerText, WarningText, ExceptionText, Invalid, Null, Name, String, Number, Boolean, Scalar, LevelVerbose, LevelDebug, LevelInformation, LevelWarning, LevelError, LevelFatal } internal struct BepInExStyleReset : IDisposable { private readonly BepInExConsoleTheme _theme; private readonly TextWriter _output; private readonly BepInExLogContext _logContext; public BepInExStyleReset(BepInExConsoleTheme theme, BepInExLogContext context, TextWriter output) { _theme = theme; _output = output; _logContext = context; } public void Dispose() { _theme.Reset(_logContext, _output); } } internal class EmptyBepInExConsoleTheme : BepInExConsoleTheme { public override bool CanBuffer => true; protected override int GetResetCharCount(BepInExLogContext context) { return 0; } public override int Set(BepInExLogContext context, TextWriter output, BepInExConsoleThemeStyle style) { return 0; } public override void Reset(BepInExLogContext context, TextWriter output) { } } public sealed class MessageClass : ILogEventEnricher { public const string PropertyName = "MessageClass"; public static MessageClass Default = new MessageClass("Default", BepInExConsoleThemeStyle.BepInExText); public static MessageClass Standard = new MessageClass("Standard", BepInExConsoleThemeStyle.Text); public static MessageClass Success = new MessageClass("Success", BepInExConsoleThemeStyle.SuccessText); public static MessageClass Danger = new MessageClass("Danger", BepInExConsoleThemeStyle.DangerText); public static MessageClass Warning = new MessageClass("Warning", BepInExConsoleThemeStyle.WarningText); public string Name { get; } public BepInExConsoleThemeStyle Style { get; } private MessageClass(string name, BepInExConsoleThemeStyle style) { Name = name; Style = style; } public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown if (logEvent == null) { throw new ArgumentNullException("logEvent"); } if (propertyFactory == null) { throw new ArgumentNullException("propertyFactory"); } logEvent.AddOrUpdateProperty(new LogEventProperty("MessageClass", (LogEventPropertyValue)new ScalarValue((object)this))); } } } namespace Serilog.Sinks.BepInEx.Rendering { internal static class AlignmentExtensions { public static Alignment Widen(this Alignment alignment, int amount) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) return new Alignment(((Alignment)(ref alignment)).Direction, ((Alignment)(ref alignment)).Width + amount); } } internal static class Casing { public static string Format(string value, string? format = null) { if (!(format == "u")) { if (format == "w") { return value.ToLowerInvariant(); } return value; } return value.ToUpperInvariant(); } } internal static class Padding { private static readonly char[] PaddingChars = new string(' ', 80).ToCharArray(); public static void Apply(TextWriter output, string value, Alignment? alignment) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Invalid comparison between Unknown and I4 if (alignment.HasValue) { int length = value.Length; Alignment value2 = alignment.Value; if (length < ((Alignment)(ref value2)).Width) { value2 = alignment.Value; int num = ((Alignment)(ref value2)).Width - value.Length; value2 = alignment.Value; if ((int)((Alignment)(ref value2)).Direction == 0) { output.Write(value); } if (num <= PaddingChars.Length) { output.Write(PaddingChars, 0, num); } else { output.Write(new string(' ', num)); } value2 = alignment.Value; if ((int)((Alignment)(ref value2)).Direction == 1) { output.Write(value); } return; } } output.Write(value); } } internal class ThemedMessageTemplateRenderer { private readonly BepInExConsoleTheme _theme; private readonly ThemedValueFormatter _valueFormatter; private readonly bool _isLiteral; private static readonly BepInExConsoleTheme NoTheme = new EmptyBepInExConsoleTheme(); private readonly ThemedValueFormatter _unthemedValueFormatter; public ThemedMessageTemplateRenderer(BepInExConsoleTheme theme, ThemedValueFormatter valueFormatter, bool isLiteral) { _theme = theme ?? throw new ArgumentNullException("theme"); _valueFormatter = valueFormatter; _isLiteral = isLiteral; _unthemedValueFormatter = valueFormatter.SwitchTheme(NoTheme); } public int Render(MessageTemplate template, IReadOnlyDictionary<string, LogEventPropertyValue> properties, BepInExLogContext context, TextWriter output) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown int num = 0; foreach (MessageTemplateToken token in template.Tokens) { TextToken val = (TextToken)(object)((token is TextToken) ? token : null); if (val != null) { num += RenderTextToken(val, properties, context, output); continue; } PropertyToken pt = (PropertyToken)token; num += RenderPropertyToken(pt, properties, context, output); } return num; } private int RenderTextToken(TextToken tt, IReadOnlyDictionary<string, LogEventPropertyValue> properties, BepInExLogContext context, TextWriter output) { IReadOnlyDictionary<string, LogEventPropertyValue> properties2 = properties; int invisibleCharacterCount = 0; using (_theme.Apply(context, output, GetDefaultedContextTextThemeStyle(), ref invisibleCharacterCount)) { output.Write(tt.Text); return invisibleCharacterCount; } BepInExConsoleThemeStyle? GetContextTextThemeStyle() { if (!properties2.TryGetValue("MessageClass", out LogEventPropertyValue value)) { return null; } ScalarValue val = (ScalarValue)(object)((value is ScalarValue) ? value : null); if (val == null) { return null; } if (val.Value is MessageClass messageClass) { return messageClass.Style; } return null; } BepInExConsoleThemeStyle GetDefaultedContextTextThemeStyle() { return GetContextTextThemeStyle() ?? MessageClass.Default.Style; } } private int RenderPropertyToken(PropertyToken pt, IReadOnlyDictionary<string, LogEventPropertyValue> properties, BepInExLogContext context, TextWriter output) { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) if (!properties.TryGetValue(pt.PropertyName, out LogEventPropertyValue value)) { int invisibleCharacterCount = 0; using (_theme.Apply(context, output, BepInExConsoleThemeStyle.Invalid, ref invisibleCharacterCount)) { output.Write(((object)pt).ToString()); return invisibleCharacterCount; } } if (!pt.Alignment.HasValue) { return RenderValue(_theme, _valueFormatter, value, context, output, pt.Format); } StringWriter stringWriter = new StringWriter(); if (!_theme.CanBuffer) { return RenderAlignedPropertyTokenUnbuffered(pt, context, output, value); } int num = RenderValue(_theme, _valueFormatter, value, context, stringWriter, pt.Format); string text = stringWriter.ToString(); int num2 = text.Length - num; Alignment value2 = pt.Alignment.Value; if (num2 >= ((Alignment)(ref value2)).Width) { output.Write(text); } else { Padding.Apply(output, text, pt.Alignment.Value.Widen(num)); } return num; } private int RenderAlignedPropertyTokenUnbuffered(PropertyToken pt, BepInExLogContext context, TextWriter output, LogEventPropertyValue propertyValue) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) if (!pt.Alignment.HasValue) { throw new ArgumentException("The PropertyToken should have a non-null Alignment.", "pt"); } StringWriter stringWriter = new StringWriter(); RenderValue(NoTheme, _unthemedValueFormatter, propertyValue, context, stringWriter, pt.Format); int length = stringWriter.ToString().Length; Alignment value = pt.Alignment.Value; if (length >= ((Alignment)(ref value)).Width) { return RenderValue(_theme, _valueFormatter, propertyValue, context, output, pt.Format); } value = pt.Alignment.Value; if ((int)((Alignment)(ref value)).Direction == 0) { int result = RenderValue(_theme, _valueFormatter, propertyValue, context, output, pt.Format); Padding.Apply(output, string.Empty, pt.Alignment.Value.Widen(-length)); return result; } Padding.Apply(output, string.Empty, pt.Alignment.Value.Widen(-length)); return RenderValue(_theme, _valueFormatter, propertyValue, context, output, pt.Format); } private int RenderValue(BepInExConsoleTheme theme, ThemedValueFormatter valueFormatter, LogEventPropertyValue propertyValue, BepInExLogContext context, TextWriter output, string? format) { if (_isLiteral) { ScalarValue val = (ScalarValue)(object)((propertyValue is ScalarValue) ? propertyValue : null); if (val != null && val.Value is string) { int invisibleCharacterCount = 0; using (theme.Apply(context, output, BepInExConsoleThemeStyle.String, ref invisibleCharacterCount)) { output.Write(val.Value); return invisibleCharacterCount; } } } return valueFormatter.Format(propertyValue, context, output, format, _isLiteral); } } } namespace Serilog.Sinks.BepInEx.Output { internal class EventPropertyTokenRenderer : OutputTemplateTokenRenderer { private readonly BepInExConsoleTheme _theme; private readonly PropertyToken _token; private readonly IFormatProvider? _formatProvider; public EventPropertyTokenRenderer(BepInExConsoleTheme theme, PropertyToken token, IFormatProvider? formatProvider) { _theme = theme; _token = token; _formatProvider = formatProvider; } public override void Render(LogEvent logEvent, BepInExLogContext context, TextWriter output) { if (!logEvent.Properties.TryGetValue(_token.PropertyName, out var value)) { Padding.Apply(output, string.Empty, _token.Alignment); return; } int invisibleCharacterCount = 0; using (_theme.Apply(context, output, BepInExConsoleThemeStyle.SecondaryText, ref invisibleCharacterCount)) { TextWriter textWriter = (_token.Alignment.HasValue ? new StringWriter() : output); ScalarValue val = (ScalarValue)(object)((value is ScalarValue) ? value : null); if (val != null && val.Value is string value2) { string value3 = Casing.Format(value2, _token.Format); textWriter.Write(value3); } else { value.Render(textWriter, _token.Format, _formatProvider); } if (_token.Alignment.HasValue) { string value4 = textWriter.ToString(); Padding.Apply(output, value4, _token.Alignment); } } } } internal class ExceptionTokenRenderer : OutputTemplateTokenRenderer { private readonly BepInExConsoleTheme _theme; private const ExceptionRenderStyleFlags ExceptionRenderStyle = ExceptionRenderStyleFlags.IncludeInner | ExceptionRenderStyleFlags.IncludeStackTrace | ExceptionRenderStyleFlags.IncludeType; public ExceptionTokenRenderer(BepInExConsoleTheme theme, PropertyToken pt) { _theme = theme; } public override void Render(LogEvent logEvent, BepInExLogContext context, TextWriter output) { if (logEvent.Exception == null) { return; } StringReader stringReader = new StringReader(logEvent.RenderException(ExceptionRenderStyleFlags.IncludeInner | ExceptionRenderStyleFlags.IncludeStackTrace | ExceptionRenderStyleFlags.IncludeType)); while (true) { string text = stringReader.ReadLine(); if (text != null) { BepInExConsoleThemeStyle style = (LineIsStackTrace(text) ? BepInExConsoleThemeStyle.TertiaryText : BepInExConsoleThemeStyle.ExceptionText); int invisibleCharacterCount = 0; using (_theme.Apply(context, output, style, ref invisibleCharacterCount)) { output.Write(text); } output.WriteLine(); continue; } break; } static int LeadingSpaceCount(string line) { return line.TakeWhile((char c) => c == ' ').Count(); } static bool LineIsStackTrace(string line) { return LeadingSpaceCount(line) % 4 == 3; } } } internal static class LevelOutputFormat { private static readonly string[][] TitleCaseLevelMap = new string[6][] { new string[7] { "V", "Vb", "Vrb", "Verb", "Verbo", "Verbos", "Verbose" }, new string[5] { "D", "De", "Dbg", "Dbug", "Debug" }, new string[11] { "I", "In", "Inf", "Info", "Infor", "Inform", "Informa", "Informat", "Informati", "Informatio", "Information" }, new string[7] { "W", "Wn", "Wrn", "Warn", "Warni", "Warnin", "Warning" }, new string[5] { "E", "Er", "Err", "Eror", "Error" }, new string[5] { "F", "Fa", "Ftl", "Fatl", "Fatal" } }; private static readonly string[][] LowerCaseLevelMap = new string[6][] { new string[7] { "v", "vb", "vrb", "verb", "verbo", "verbos", "verbose" }, new string[5] { "d", "de", "dbg", "dbug", "debug" }, new string[11] { "i", "in", "inf", "info", "infor", "inform", "informa", "informat", "informati", "informatio", "information" }, new string[7] { "w", "wn", "wrn", "warn", "warni", "warnin", "warning" }, new string[5] { "e", "er", "err", "eror", "error" }, new string[5] { "f", "fa", "ftl", "fatl", "fatal" } }; private static readonly string[][] UpperCaseLevelMap = new string[6][] { new string[7] { "V", "VB", "VRB", "VERB", "VERBO", "VERBOS", "VERBOSE" }, new string[5] { "D", "DE", "DBG", "DBUG", "DEBUG" }, new string[11] { "I", "IN", "INF", "INFO", "INFOR", "INFORM", "INFORMA", "INFORMAT", "INFORMATI", "INFORMATIO", "INFORMATION" }, new string[7] { "W", "WN", "WRN", "WARN", "WARNI", "WARNIN", "WARNING" }, new string[5] { "E", "ER", "ERR", "EROR", "ERROR" }, new string[5] { "F", "FA", "FTL", "FATL", "FATAL" } }; public static string GetLevelMoniker(LogEventLevel value, string? format = null) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Expected I4, but got Unknown int num = (int)value; if ((num < 0 || num > 5) ? true : false) { return Casing.Format(((object)(LogEventLevel)(ref value)).ToString(), format); } if (format == null || (format.Length != 2 && format.Length != 3)) { return Casing.Format(GetLevelMoniker(TitleCaseLevelMap, num), format); } int num2 = format[1] - 48; if (format.Length == 3) { num2 *= 10; num2 += format[2] - 48; } if (num2 < 1) { return string.Empty; } return format[0] switch { 'w' => GetLevelMoniker(LowerCaseLevelMap, num, num2), 'u' => GetLevelMoniker(UpperCaseLevelMap, num, num2), 't' => GetLevelMoniker(TitleCaseLevelMap, num, num2), _ => Casing.Format(GetLevelMoniker(TitleCaseLevelMap, num), format), }; } private static string GetLevelMoniker(string[][] caseLevelMap, int index, int width) { string[] array = caseLevelMap[index]; return array[Math.Min(width, array.Length) - 1]; } private static string GetLevelMoniker(string[][] caseLevelMap, int index) { return caseLevelMap[index][^1]; } } internal class LevelTokenRenderer : OutputTemplateTokenRenderer { private readonly BepInExConsoleTheme _theme; private readonly PropertyToken _levelToken; private static readonly Dictionary<LogEventLevel, BepInExConsoleThemeStyle> Levels = new Dictionary<LogEventLevel, BepInExConsoleThemeStyle> { { (LogEventLevel)0, BepInExConsoleThemeStyle.LevelVerbose }, { (LogEventLevel)1, BepInExConsoleThemeStyle.LevelDebug }, { (LogEventLevel)2, BepInExConsoleThemeStyle.LevelInformation }, { (LogEventLevel)3, BepInExConsoleThemeStyle.LevelWarning }, { (LogEventLevel)4, BepInExConsoleThemeStyle.LevelError }, { (LogEventLevel)5, BepInExConsoleThemeStyle.LevelFatal } }; public LevelTokenRenderer(BepInExConsoleTheme theme, PropertyToken levelToken) { _theme = theme; _levelToken = levelToken; } public override void Render(LogEvent logEvent, BepInExLogContext context, TextWriter output) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) string levelMoniker = LevelOutputFormat.GetLevelMoniker(logEvent.Level, _levelToken.Format); if (!Levels.TryGetValue(logEvent.Level, out var value)) { value = BepInExConsoleThemeStyle.Invalid; } int invisibleCharacterCount = 0; using (_theme.Apply(context, output, value, ref invisibleCharacterCount)) { Padding.Apply(output, levelMoniker, _levelToken.Alignment); } } } internal class MessageTemplateOutputTokenRenderer : OutputTemplateTokenRenderer { private readonly BepInExConsoleTheme _theme; private readonly PropertyToken _token; private readonly ThemedMessageTemplateRenderer _renderer; public MessageTemplateOutputTokenRenderer(BepInExConsoleTheme theme, PropertyToken token, IFormatProvider? formatProvider) { _theme = theme ?? throw new ArgumentNullException("theme"); _token = token ?? throw new ArgumentNullException("token"); bool isLiteral = false; bool flag = false; if (token.Format != null) { for (int i = 0; i < token.Format.Length; i++) { if (token.Format[i] == 'l') { isLiteral = true; } else if (token.Format[i] == 'j') { flag = true; } } } _renderer = new ThemedMessageTemplateRenderer(theme, flag ? ((ThemedValueFormatter)new ThemedJsonValueFormatter(theme, formatProvider)) : ((ThemedValueFormatter)new ThemedDisplayValueFormatter(theme, formatProvider)), isLiteral); } public override void Render(LogEvent logEvent, BepInExLogContext context, TextWriter output) { //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) if (!_token.Alignment.HasValue || !_theme.CanBuffer) { _renderer.Render(logEvent.MessageTemplate, logEvent.Properties, context, output); return; } StringWriter stringWriter = new StringWriter(); int amount = _renderer.Render(logEvent.MessageTemplate, logEvent.Properties, context, stringWriter); string value = stringWriter.ToString(); Padding.Apply(output, value, _token.Alignment.Value.Widen(amount)); } } internal class NewLineTokenRenderer : OutputTemplateTokenRenderer { private readonly Alignment? _alignment; public NewLineTokenRenderer(Alignment? alignment) { _alignment = alignment; } public override void Render(LogEvent logEvent, BepInExLogContext context, TextWriter output) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) if (_alignment.HasValue) { Padding.Apply(output, Environment.NewLine, _alignment.Value.Widen(Environment.NewLine.Length)); } else { output.WriteLine(); } } } internal class OutputTemplateRenderer : IBepInExTextFormatter { private readonly OutputTemplateTokenRenderer[] _renderers; public OutputTemplateRenderer(BepInExConsoleTheme theme, string outputTemplate, IFormatProvider? formatProvider) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Expected O, but got Unknown if (outputTemplate == null) { throw new ArgumentNullException("outputTemplate"); } MessageTemplate val = new MessageTemplateParser().Parse(outputTemplate); List<OutputTemplateTokenRenderer> list = new List<OutputTemplateTokenRenderer>(); foreach (MessageTemplateToken token in val.Tokens) { TextToken val2 = (TextToken)(object)((token is TextToken) ? token : null); if (val2 != null) { list.Add(new TextTokenRenderer(theme, val2.Text)); continue; } PropertyToken val3 = (PropertyToken)token; if (val3.PropertyName == "Level") { list.Add(new LevelTokenRenderer(theme, val3)); } else if (val3.PropertyName == "SourceName") { list.Add(new SourceNameRenderer(theme, val3)); } else if (val3.PropertyName == "NewLine") { list.Add(new NewLineTokenRenderer(val3.Alignment)); } else if (val3.PropertyName == "TraceId") { list.Add(new TraceIdTokenRenderer(theme, val3)); } else if (val3.PropertyName == "SpanId") { list.Add(new SpanIdTokenRenderer(theme, val3)); } else if (val3.PropertyName == "Exception") { list.Add(new ExceptionTokenRenderer(theme, val3)); } else if (val3.PropertyName == "Message") { list.Add(new MessageTemplateOutputTokenRenderer(theme, val3, formatProvider)); } else if (val3.PropertyName == "Timestamp") { list.Add(new TimestampTokenRenderer(theme, val3, formatProvider)); } else if (val3.PropertyName == "Properties") { list.Add(new PropertiesTokenRenderer(theme, val3, val, formatProvider)); } else { list.Add(new EventPropertyTokenRenderer(theme, val3, formatProvider)); } } _renderers = list.ToArray(); } public void Format(LogEvent logEvent, BepInExLogContext context, TextWriter output) { if (logEvent == null) { throw new ArgumentNullException("logEvent"); } if (output == null) { throw new ArgumentNullException("output"); } OutputTemplateTokenRenderer[] renderers = _renderers; for (int i = 0; i < renderers.Length; i++) { renderers[i].Render(logEvent, context, output); } } } internal abstract class OutputTemplateTokenRenderer { public abstract void Render(LogEvent logEvent, BepInExLogContext context, TextWriter output); } internal class PropertiesTokenRenderer : OutputTemplateTokenRenderer { private readonly MessageTemplate _outputTemplate; private readonly BepInExConsoleTheme _theme; private readonly PropertyToken _token; private readonly ThemedValueFormatter _valueFormatter; public PropertiesTokenRenderer(BepInExConsoleTheme theme, PropertyToken token, MessageTemplate outputTemplate, IFormatProvider? formatProvider) { _outputTemplate = outputTemplate; _theme = theme ?? throw new ArgumentNullException("theme"); _token = token ?? throw new ArgumentNullException("token"); bool flag = false; if (token.Format != null) { for (int i = 0; i < token.Format.Length; i++) { if (token.Format[i] == 'j') { flag = true; } } } _valueFormatter = (flag ? ((ThemedValueFormatter)new ThemedJsonValueFormatter(theme, formatProvider)) : ((ThemedValueFormatter)new ThemedDisplayValueFormatter(theme, formatProvider))); } public override void Render(LogEvent logEvent, BepInExLogContext context, TextWriter output) { //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) LogEvent logEvent2 = logEvent; StructureValue val = new StructureValue(logEvent2.Properties.Where((KeyValuePair<string, LogEventPropertyValue> p) => !TemplateContainsPropertyName(logEvent2.MessageTemplate, p.Key) && !TemplateContainsPropertyName(_outputTemplate, p.Key)).Select((Func<KeyValuePair<string, LogEventPropertyValue>, LogEventProperty>)((KeyValuePair<string, LogEventPropertyValue> p) => new LogEventProperty(p.Key, p.Value))), (string)null); if (!_token.Alignment.HasValue || !_theme.CanBuffer) { _valueFormatter.Format((LogEventPropertyValue)(object)val, context, output, null); return; } StringWriter stringWriter = new StringWriter(new StringBuilder(val.Properties.Count * 16)); int amount = _valueFormatter.Format((LogEventPropertyValue)(object)val, context, stringWriter, null); string value = stringWriter.ToString(); Padding.Apply(output, value, _token.Alignment.Value.Widen(amount)); } private static bool TemplateContainsPropertyName(MessageTemplate template, string propertyName) { foreach (MessageTemplateToken token in template.Tokens) { PropertyToken val = (PropertyToken)(object)((token is PropertyToken) ? token : null); if (val != null && val.PropertyName == propertyName) { return true; } } return false; } } internal class SourceNameRenderer : OutputTemplateTokenRenderer { private readonly BepInExConsoleTheme _theme; private readonly PropertyToken _sourceNameToken; public SourceNameRenderer(BepInExConsoleTheme theme, PropertyToken sourceNameToken) { _theme = theme; _sourceNameToken = sourceNameToken; } public override void Render(LogEvent logEvent, BepInExLogContext context, TextWriter output) { int invisibleCharacterCount = 0; using (_theme.Apply(context, output, BepInExConsoleThemeStyle.SecondaryText, ref invisibleCharacterCount)) { Padding.Apply(output, context.SourceName, _sourceNameToken.Alignment); } } } internal class SpanIdTokenRenderer : OutputTemplateTokenRenderer { private readonly BepInExConsoleTheme _theme; private readonly Alignment? _alignment; public SpanIdTokenRenderer(BepInExConsoleTheme theme, PropertyToken spanIdToken) { _theme = theme; _alignment = spanIdToken.Alignment; } public override void Render(LogEvent logEvent, BepInExLogContext context, TextWriter output) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) ActivitySpanId? spanId = logEvent.SpanId; if (!spanId.HasValue) { return; } ActivitySpanId valueOrDefault = spanId.GetValueOrDefault(); int invisibleCharacterCount = 0; using (_theme.Apply(context, output, BepInExConsoleThemeStyle.Text, ref invisibleCharacterCount)) { Alignment? alignment = _alignment; if (alignment.HasValue) { Alignment valueOrDefault2 = alignment.GetValueOrDefault(); Padding.Apply(output, valueOrDefault.ToString(), valueOrDefault2); } else { output.Write(valueOrDefault); } } } } internal class TextTokenRenderer : OutputTemplateTokenRenderer { private readonly BepInExConsoleTheme _theme; private readonly string _text; public TextTokenRenderer(BepInExConsoleTheme theme, string text) { _theme = theme; _text = text; } public override void Render(LogEvent logEvent, BepInExLogContext context, TextWriter output) { int invisibleCharacterCount = 0; using (_theme.Apply(context, output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { output.Write(_text); } } } internal class TimestampTokenRenderer : OutputTemplateTokenRenderer { private readonly struct DateTimeOffsetValue { public DateTimeOffset Value { get; } public DateTimeOffsetValue(DateTimeOffset value) { Value = value; } public void Render(TextWriter output, string? format = null, IFormatProvider? formatProvider = null) { ICustomFormatter customFormatter = (ICustomFormatter)(formatProvider?.GetFormat(typeof(ICustomFormatter))); if (customFormatter != null) { output.Write(customFormatter.Format(format, Value, formatProvider)); } else { output.Write(Value.ToString(format, formatProvider ?? CultureInfo.InvariantCulture)); } } } private readonly BepInExConsoleTheme _theme; private readonly PropertyToken _token; private readonly IFormatProvider? _formatProvider; public TimestampTokenRenderer(BepInExConsoleTheme theme, PropertyToken token, IFormatProvider? formatProvider) { _theme = theme; _token = token; _formatProvider = formatProvider; } public override void Render(LogEvent logEvent, BepInExLogContext context, TextWriter output) { DateTimeOffsetValue dateTimeOffsetValue = new DateTimeOffsetValue(logEvent.Timestamp); int invisibleCharacterCount = 0; using (_theme.Apply(context, output, BepInExConsoleThemeStyle.SecondaryText, ref invisibleCharacterCount)) { if (!_token.Alignment.HasValue) { dateTimeOffsetValue.Render(output, _token.Format, _formatProvider); return; } StringWriter stringWriter = new StringWriter(); dateTimeOffsetValue.Render(stringWriter, _token.Format, _formatProvider); string value = stringWriter.ToString(); Padding.Apply(output, value, _token.Alignment); } } } internal class TraceIdTokenRenderer : OutputTemplateTokenRenderer { private readonly BepInExConsoleTheme _theme; private readonly Alignment? _alignment; public TraceIdTokenRenderer(BepInExConsoleTheme theme, PropertyToken traceIdToken) { _theme = theme; _alignment = traceIdToken.Alignment; } public override void Render(LogEvent logEvent, BepInExLogContext context, TextWriter output) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) ActivityTraceId? traceId = logEvent.TraceId; if (!traceId.HasValue) { return; } ActivityTraceId valueOrDefault = traceId.GetValueOrDefault(); int invisibleCharacterCount = 0; using (_theme.Apply(context, output, BepInExConsoleThemeStyle.Text, ref invisibleCharacterCount)) { Alignment? alignment = _alignment; if (alignment.HasValue) { Alignment valueOrDefault2 = alignment.GetValueOrDefault(); Padding.Apply(output, valueOrDefault.ToString(), valueOrDefault2); } else { output.Write(valueOrDefault); } } } } } namespace Serilog.Sinks.BepInEx.Formatting { public interface IBepInExTextFormatter { void Format(LogEvent logEvent, BepInExLogContext context, TextWriter output); } internal class ThemedDisplayValueFormatter : ThemedValueFormatter { private readonly IFormatProvider? _formatProvider; public ThemedDisplayValueFormatter(BepInExConsoleTheme theme, IFormatProvider? formatProvider) : base(theme) { _formatProvider = formatProvider; } public override ThemedValueFormatter SwitchTheme(BepInExConsoleTheme theme) { return new ThemedDisplayValueFormatter(theme, _formatProvider); } protected override int VisitScalarValue(ThemedValueFormatterState state, ScalarValue scalar) { if (scalar == null) { throw new ArgumentNullException("scalar"); } return FormatLiteralValue(scalar, state.LogContext, state.Output, state.Format); } protected override int VisitSequenceValue(ThemedValueFormatterState state, SequenceValue sequence) { if (sequence == null) { throw new ArgumentNullException("sequence"); } int invisibleCharacterCount = 0; using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write('['); } string text = string.Empty; for (int i = 0; i < sequence.Elements.Count; i++) { if (text.Length != 0) { using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write(text); } } text = ", "; ((LogEventPropertyValueVisitor<ThemedValueFormatterState, int>)this).Visit(state, sequence.Elements[i]); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write(']'); return invisibleCharacterCount; } } protected override int VisitStructureValue(ThemedValueFormatterState state, StructureValue structure) { int invisibleCharacterCount = 0; if (structure.TypeTag != null) { using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.Name, ref invisibleCharacterCount)) { state.Output.Write(structure.TypeTag); } state.Output.Write(' '); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write('{'); } string text = string.Empty; for (int i = 0; i < structure.Properties.Count; i++) { if (text.Length != 0) { using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write(text); } } text = ", "; LogEventProperty val = structure.Properties[i]; using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.Name, ref invisibleCharacterCount)) { state.Output.Write(val.Name); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write('='); } invisibleCharacterCount += ((LogEventPropertyValueVisitor<ThemedValueFormatterState, int>)this).Visit(state.Nest(), val.Value); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write('}'); return invisibleCharacterCount; } } protected override int VisitDictionaryValue(ThemedValueFormatterState state, DictionaryValue dictionary) { int invisibleCharacterCount = 0; using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write('{'); } string text = string.Empty; foreach (KeyValuePair<ScalarValue, LogEventPropertyValue> element in dictionary.Elements) { if (text.Length != 0) { using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write(text); } } text = ", "; using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write('['); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.String, ref invisibleCharacterCount)) { invisibleCharacterCount += ((LogEventPropertyValueVisitor<ThemedValueFormatterState, int>)this).Visit(state.Nest(), (LogEventPropertyValue)(object)element.Key); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write("]="); } invisibleCharacterCount += ((LogEventPropertyValueVisitor<ThemedValueFormatterState, int>)this).Visit(state.Nest(), element.Value); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write('}'); return invisibleCharacterCount; } } public int FormatLiteralValue(ScalarValue scalar, BepInExLogContext context, TextWriter output, string? format) { object value = scalar.Value; int invisibleCharacterCount = 0; if (value == null) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Null, ref invisibleCharacterCount)) { output.Write("null"); return invisibleCharacterCount; } } if (value is string text) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.String, ref invisibleCharacterCount)) { if (format != "l") { JsonValueFormatter.WriteQuotedJsonString(text, output); } else { output.Write(text); } } return invisibleCharacterCount; } if (value is ValueType) { if (value is int || value is uint || value is long || value is ulong || value is decimal || value is byte || value is sbyte || value is short || value is ushort || value is float || value is double) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Number, ref invisibleCharacterCount)) { ((LogEventPropertyValue)scalar).Render(output, format, _formatProvider); return invisibleCharacterCount; } } if (value is bool value2) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Boolean, ref invisibleCharacterCount)) { output.Write(value2); return invisibleCharacterCount; } } if (value is char value3) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Scalar, ref invisibleCharacterCount)) { output.Write('\''); output.Write(value3); output.Write('\''); return invisibleCharacterCount; } } } using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Scalar, ref invisibleCharacterCount)) { ((LogEventPropertyValue)scalar).Render(output, format, _formatProvider); return invisibleCharacterCount; } } } internal class ThemedJsonValueFormatter : ThemedValueFormatter { private readonly ThemedDisplayValueFormatter _displayFormatter; private readonly IFormatProvider? _formatProvider; public ThemedJsonValueFormatter(BepInExConsoleTheme theme, IFormatProvider? formatProvider) : base(theme) { _displayFormatter = new ThemedDisplayValueFormatter(theme, formatProvider); _formatProvider = formatProvider; } public override ThemedValueFormatter SwitchTheme(BepInExConsoleTheme theme) { return new ThemedJsonValueFormatter(theme, _formatProvider); } protected override int VisitScalarValue(ThemedValueFormatterState state, ScalarValue scalar) { if (scalar == null) { throw new ArgumentNullException("scalar"); } if (state.IsTopLevel) { return _displayFormatter.FormatLiteralValue(scalar, state.LogContext, state.Output, state.Format); } return FormatLiteralValue(scalar, state.LogContext, state.Output); } protected override int VisitSequenceValue(ThemedValueFormatterState state, SequenceValue sequence) { if (sequence == null) { throw new ArgumentNullException("sequence"); } int invisibleCharacterCount = 0; using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write('['); } string text = string.Empty; for (int i = 0; i < sequence.Elements.Count; i++) { if (text.Length != 0) { using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write(text); } } text = ", "; ((LogEventPropertyValueVisitor<ThemedValueFormatterState, int>)this).Visit(state.Nest(), sequence.Elements[i]); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write(']'); return invisibleCharacterCount; } } protected override int VisitStructureValue(ThemedValueFormatterState state, StructureValue structure) { int invisibleCharacterCount = 0; using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write('{'); } string text = string.Empty; for (int i = 0; i < structure.Properties.Count; i++) { if (text.Length != 0) { using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write(text); } } text = ", "; LogEventProperty val = structure.Properties[i]; using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.Name, ref invisibleCharacterCount)) { JsonValueFormatter.WriteQuotedJsonString(val.Name, state.Output); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write(": "); } invisibleCharacterCount += ((LogEventPropertyValueVisitor<ThemedValueFormatterState, int>)this).Visit(state.Nest(), val.Value); } if (structure.TypeTag != null) { using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write(text); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.Name, ref invisibleCharacterCount)) { JsonValueFormatter.WriteQuotedJsonString("$type", state.Output); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write(": "); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.String, ref invisibleCharacterCount)) { JsonValueFormatter.WriteQuotedJsonString(structure.TypeTag, state.Output); } } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write('}'); return invisibleCharacterCount; } } protected override int VisitDictionaryValue(ThemedValueFormatterState state, DictionaryValue dictionary) { int invisibleCharacterCount = 0; using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write('{'); } string text = string.Empty; foreach (KeyValuePair<ScalarValue, LogEventPropertyValue> element in dictionary.Elements) { if (text.Length != 0) { using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write(text); } } text = ", "; BepInExConsoleThemeStyle style = ((element.Key.Value == null) ? BepInExConsoleThemeStyle.Null : ((element.Key.Value is string) ? BepInExConsoleThemeStyle.String : BepInExConsoleThemeStyle.Scalar)); using (ApplyStyle(state.LogContext, state.Output, style, ref invisibleCharacterCount)) { JsonValueFormatter.WriteQuotedJsonString((element.Key.Value ?? "null").ToString() ?? "", state.Output); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write(": "); } invisibleCharacterCount += ((LogEventPropertyValueVisitor<ThemedValueFormatterState, int>)this).Visit(state.Nest(), element.Value); } using (ApplyStyle(state.LogContext, state.Output, BepInExConsoleThemeStyle.TertiaryText, ref invisibleCharacterCount)) { state.Output.Write('}'); return invisibleCharacterCount; } } private int FormatLiteralValue(ScalarValue scalar, BepInExLogContext context, TextWriter output) { object value = scalar.Value; int invisibleCharacterCount = 0; if (value == null) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Null, ref invisibleCharacterCount)) { output.Write("null"); return invisibleCharacterCount; } } if (value is string text) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.String, ref invisibleCharacterCount)) { JsonValueFormatter.WriteQuotedJsonString(text, output); return invisibleCharacterCount; } } if (value is ValueType) { if (value is int || value is uint || value is long || value is ulong || value is decimal || value is byte || value is sbyte || value is short || value is ushort) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Number, ref invisibleCharacterCount)) { output.Write(((IFormattable)value).ToString(null, CultureInfo.InvariantCulture)); return invisibleCharacterCount; } } if (value is double d) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Number, ref invisibleCharacterCount)) { if (double.IsNaN(d) || double.IsInfinity(d)) { JsonValueFormatter.WriteQuotedJsonString(d.ToString(CultureInfo.InvariantCulture), output); } else { output.Write(d.ToString("R", CultureInfo.InvariantCulture)); } } return invisibleCharacterCount; } if (value is float num) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Number, ref invisibleCharacterCount)) { if (double.IsNaN(num) || double.IsInfinity(num)) { JsonValueFormatter.WriteQuotedJsonString(num.ToString(CultureInfo.InvariantCulture), output); } else { output.Write(num.ToString("R", CultureInfo.InvariantCulture)); } } return invisibleCharacterCount; } if (value is bool flag) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Boolean, ref invisibleCharacterCount)) { output.Write(flag ? "true" : "false"); return invisibleCharacterCount; } } if (value is char c) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Scalar, ref invisibleCharacterCount)) { JsonValueFormatter.WriteQuotedJsonString(c.ToString(), output); return invisibleCharacterCount; } } if (value is DateTime || value is DateTimeOffset) { using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Scalar, ref invisibleCharacterCount)) { output.Write('"'); output.Write(((IFormattable)value).ToString("O", CultureInfo.InvariantCulture)); output.Write('"'); return invisibleCharacterCount; } } } using (ApplyStyle(context, output, BepInExConsoleThemeStyle.Scalar, ref invisibleCharacterCount)) { JsonValueFormatter.WriteQuotedJsonString(value.ToString() ?? "", output); return invisibleCharacterCount; } } } internal abstract class ThemedValueFormatter : LogEventPropertyValueVisitor<ThemedValueFormatterState, int> { private readonly BepInExConsoleTheme _theme; protected ThemedValueFormatter(BepInExConsoleTheme theme) { _theme = theme ?? throw new ArgumentNullException("theme"); } protected BepInExStyleReset ApplyStyle(BepInExLogContext context, TextWriter output, BepInExConsoleThemeStyle style, ref int invisibleCharacterCount) { return _theme.Apply(context, output, style, ref invisibleCharacterCount); } public int Format(LogEventPropertyValue value, BepInExLogContext context, TextWriter output, string? format, bool literalTopLevel = false) { return ((LogEventPropertyValueVisitor<ThemedValueFormatterState, int>)this).Visit(new ThemedValueFormatterState { LogContext = context, Output = output, Format = format, IsTopLevel = literalTopLevel }, value); } public abstract ThemedValueFormatter SwitchTheme(BepInExConsoleTheme theme); } internal struct ThemedValueFormatterState { public BepInExLogContext LogContext; public TextWriter Output; public string? Format; public bool IsTopLevel; public ThemedValueFormatterState Nest() { ThemedValueFormatterState result = default(ThemedValueFormatterState); result.LogContext = LogContext; result.Output = Output; return result; } } } namespace Serilog.Sinks.BepInEx.Formatting.Display { public static class OutputProperties { public const string SourceNamePropertyName = "SourceName"; } } namespace Serilog.Sinks.BepInEx.Extensions { public static class ExceptionExtensions { private static string InnerExceptionDelimiter => string.Concat(Environment.NewLine, string.Concat(Enumerable.Repeat("─", 10)), Environment.NewLine, Environment.NewLine); public static string Render(this Exception exception, ExceptionRenderStyleFlags style, ExceptionRenderStyleFlags? recursiveStyle = null) { ExceptionRenderStyleFlags valueOrDefault = recursiveStyle.GetValueOrDefault(); if (!recursiveStyle.HasValue) { valueOrDefault = style; recursiveStyle = valueOrDefault; } if (exception != null) { if (exception is AggregateException aggregateException) { return RenderAggregate(aggregateException, style, recursiveStyle.Value); } return RenderRecursively(exception, style, recursiveStyle.Value); } throw new ArgumentNullException("Exception", "Exception cannot be null"); } private static string RenderAggregate(AggregateException aggregateException, ExceptionRenderStyleFlags style, ExceptionRenderStyleFlags recursiveStyle) { IEnumerable<string> values = from innerException in aggregateException.Flatten().InnerExceptions select innerException.Render(style, recursiveStyle) into rendered select rendered.MultilineIndent(4); bool flag = style.Has(ExceptionRenderStyleFlags.IncludeType); return new StringBuilder(200).AppendLine(RenderKernel(aggregateException, flag) ?? "Issues:").Append(flag ? ("{" + Environment.NewLine) : string.Empty).AppendLine(string.Join(InnerExceptionDelimiter, values)) .Append(flag ? "}" : string.Empty) .ToString() .TrimEnd(); } private static string? RenderKernel(Exception exception, bool shouldIncludeType) { bool flag = !string.IsNullOrWhiteSpace(exception.Message); if (flag && shouldIncludeType) { return $"{exception.GetType()}: {exception.Message}"; } if (flag) { return exception.Message; } if (shouldIncludeType) { return exception.GetType().ToString(); } return null; } private static string RenderDefault(Exception exception, ExceptionRenderStyleFlags style) { if (style.Has(ExceptionRenderStyleFlags.IncludeInner)) { throw new NotSupportedException("RenderDefault cannot include inner exceptions. Use RenderRecursively."); } StringBuilder stringBuilder = new StringBuilder(100); stringBuilder.AppendLine(RenderKernel(exception, style.Has(ExceptionRenderStyleFlags.IncludeType)) ?? "[no message]"); if (style.Has(ExceptionRenderStyleFlags.IncludeStackTrace) && exception.StackTrace != null) { stringBuilder.AppendLine(exception.StackTrace); } return stringBuilder.ToString().TrimEnd(); } private static string RenderRecursively(Exception exception, ExceptionRenderStyleFlags style, ExceptionRenderStyleFlags recursiveStyle) { if (!style.Has(ExceptionRenderStyleFlags.IncludeInner)) { return RenderDefault(exception, style); } StringBuilder stringBuilder = new StringBuilder(100); stringBuilder.AppendLine(RenderKernel(exception, style.Has(ExceptionRenderStyleFlags.IncludeType)) ?? "[no message]"); if (style.Has(ExceptionRenderStyleFlags.IncludeStackTrace) && exception.StackTrace != null) { stringBuilder.AppendLine(exception.StackTrace); } if (style.Has(ExceptionRenderStyleFlags.IncludeInner) && exception.InnerException != null) { string text = exception.InnerException.Render(recursiveStyle).Trim(); stringBuilder.AppendLine("Caused by: " + text); } return stringBuilder.ToString().TrimEnd(); } } public static class LogEventExtensions { public static string RenderException(this LogEvent logEvent, ExceptionRenderStyleFlags styleFlags, ExceptionRenderStyleFlags? recursiveStyleFlags = null) { if (logEvent.Exception == null) { throw new InvalidOperationException("logEvent.Exception cannot be null"); } return logEvent.Exception.Render(styleFlags, recursiveStyleFlags); } } public static class LogEventLevelExtensions { public static LogLevel ToBepInExLevel(this LogEventLevel level) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected I4, but got Unknown //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) return (LogLevel)((int)level switch { 0 => 32, 1 => 16, 2 => 8, 3 => 4, 4 => 2, 5 => 1, _ => throw new ArgumentOutOfRangeException("level", level, "Unrecognised LogEventLevel"), }); } } public static class LogLevelExtensions { public static string GetLevelAnsiReset(this LogLevel level) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Invalid comparison between Unknown and I4 //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Expected I4, but got Unknown //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Invalid comparison between Unknown and I4 if ((int)level <= 8) { switch (level - 1) { default: if ((int)level != 8) { break; } return "\u001b[m"; case 3: return "\u001b[0;38;5;11m"; case 1: return "\u001b[0;1;38;5;1m"; case 0: return "\u001b[0;1;38;5;9m"; case 2: break; } } else { if ((int)level == 16) { return "\u001b[0;38;5;7m"; } if ((int)level == 32) { return "\u001b[0;38;5;8m"; } } return "\u001b[m"; } } public static class StringExtensions { public static string Indent(this string input, int spaces) { return string.Concat(string.Concat(Enumerable.Repeat(" ", spaces)), input); } public static string MultilineIndent(this string input, int spaces) { return string.Join(Environment.NewLine, from line in input.Split("\n") select line.Trim() into line select line.Indent(spaces)); } } }