using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using Serilog.Capturing;
using Serilog.Configuration;
using Serilog.Context;
using Serilog.Core;
using Serilog.Core.Enrichers;
using Serilog.Core.Filters;
using Serilog.Core.Pipeline;
using Serilog.Core.Sinks;
using Serilog.Core.Sinks.Batching;
using Serilog.Data;
using Serilog.Debugging;
using Serilog.Events;
using Serilog.Formatting.Json;
using Serilog.Parsing;
using Serilog.Policies;
using Serilog.Rendering;
using Serilog.Settings.KeyValuePairs;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: CLSCompliant(true)]
[assembly: InternalsVisibleTo("Serilog.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b81894191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066b19485ec")]
[assembly: InternalsVisibleTo("Serilog.PerformanceTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b81894191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066b19485ec")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("Serilog Contributors")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © Serilog Contributors")]
[assembly: AssemblyDescription("Simple .NET logging with fully-structured events")]
[assembly: AssemblyFileVersion("4.3.0.0")]
[assembly: AssemblyInformationalVersion("4.3.1-main-5625030+5625030e8f8fceca2e3180575aba174751ef7add")]
[assembly: AssemblyProduct("Serilog")]
[assembly: AssemblyTitle("Serilog")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/serilog/serilog")]
[assembly: AssemblyVersion("4.3.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class IsReadOnlyAttribute : Attribute
{
}
[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.Parameter, AllowMultiple = false, Inherited = false)]
internal sealed class ScopedRefAttribute : Attribute
{
}
[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;
}
}
}
internal static class Guard
{
public static T AgainstNull<T>([NoEnumeration][NotNull] T? argument, [CallerArgumentExpression("argument")] string? paramName = null) where T : class
{
if (argument == null)
{
throw new ArgumentNullException(paramName);
}
return argument;
}
}
namespace System
{
internal abstract class TimeProvider
{
private sealed class SystemTimeProvider : TimeProvider
{
}
public static TimeProvider System { get; } = new SystemTimeProvider();
public virtual long TimestampFrequency => Stopwatch.Frequency;
public DateTimeOffset GetLocalNow()
{
return DateTimeOffset.Now;
}
public virtual DateTimeOffset GetUtcNow()
{
return DateTimeOffset.UtcNow;
}
public virtual long GetTimestamp()
{
return Stopwatch.GetTimestamp();
}
public TimeSpan GetElapsedTime(long startingTimestamp, long endingTimestamp)
{
return new TimeSpan((long)((double)(endingTimestamp - startingTimestamp) * (10000000.0 / (double)TimestampFrequency)));
}
public TimeSpan GetElapsedTime(long startingTimestamp)
{
return GetElapsedTime(startingTimestamp, GetTimestamp());
}
}
[ExcludeFromCodeCoverage]
internal readonly struct Index : IEquatable<Index>
{
private static class ThrowHelper
{
[DoesNotReturn]
public static void ThrowValueArgumentOutOfRange_NeedNonNegNumException()
{
throw new ArgumentOutOfRangeException("value", "Non-negative number required.");
}
}
private readonly int _value;
public static Index Start => new Index(0);
public static Index End => new Index(-1);
public int Value
{
get
{
if (_value < 0)
{
return ~_value;
}
return _value;
}
}
public bool IsFromEnd => _value < 0;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Index(int value, bool fromEnd = false)
{
if (value < 0)
{
ThrowHelper.ThrowValueArgumentOutOfRange_NeedNonNegNumException();
}
if (fromEnd)
{
_value = ~value;
}
else
{
_value = value;
}
}
private Index(int value)
{
_value = value;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Index FromStart(int value)
{
if (value < 0)
{
ThrowHelper.ThrowValueArgumentOutOfRange_NeedNonNegNumException();
}
return new Index(value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Index FromEnd(int value)
{
if (value < 0)
{
ThrowHelper.ThrowValueArgumentOutOfRange_NeedNonNegNumException();
}
return new Index(~value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public int GetOffset(int length)
{
int num = _value;
if (IsFromEnd)
{
num += length + 1;
}
return num;
}
public override bool Equals([NotNullWhen(true)] object? value)
{
if (value is Index)
{
return _value == ((Index)value)._value;
}
return false;
}
public bool Equals(Index other)
{
return _value == other._value;
}
public override int GetHashCode()
{
return _value;
}
public static implicit operator Index(int value)
{
return FromStart(value);
}
public override string ToString()
{
if (IsFromEnd)
{
return ToStringFromEnd();
}
return ((uint)Value).ToString();
}
private string ToStringFromEnd()
{
return "^" + Value;
}
}
[ExcludeFromCodeCoverage]
internal readonly struct Range : IEquatable<Range>
{
private static class HashHelpers
{
public static int Combine(int h1, int h2)
{
return (((h1 << 5) | (h1 >>> 27)) + h1) ^ h2;
}
}
private static class ThrowHelper
{
[DoesNotReturn]
public static void ThrowArgumentOutOfRangeException()
{
throw new ArgumentOutOfRangeException("length");
}
}
public Index Start { get; }
public Index End { get; }
public static Range All => Index.Start..Index.End;
public Range(Index start, Index end)
{
Start = start;
End = end;
}
public override bool Equals([NotNullWhen(true)] object? value)
{
if (value is Range range && range.Start.Equals(Start))
{
return range.End.Equals(End);
}
return false;
}
public bool Equals(Range other)
{
if (other.Start.Equals(Start))
{
return other.End.Equals(End);
}
return false;
}
public override int GetHashCode()
{
return HashHelpers.Combine(Start.GetHashCode(), End.GetHashCode());
}
public override string ToString()
{
return Start.ToString() + ".." + End;
}
public static Range StartAt(Index start)
{
return start..Index.End;
}
public static Range EndAt(Index end)
{
return Index.Start..end;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (int Offset, int Length) GetOffsetAndLength(int length)
{
Index start = Start;
int num = ((!start.IsFromEnd) ? start.Value : (length - start.Value));
Index end = End;
int num2 = ((!end.IsFromEnd) ? end.Value : (length - end.Value));
if ((uint)num2 > (uint)length || (uint)num > (uint)num2)
{
ThrowHelper.ThrowArgumentOutOfRangeException();
}
return (num, num2 - num);
}
}
}
namespace System.Runtime.InteropServices
{
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class SuppressGCTransitionAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class UnmanagedCallersOnlyAttribute : Attribute
{
public Type[]? CallConvs;
public string? EntryPoint;
}
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class WasmImportLinkageAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices2
{
[AttributeUsage(AttributeTargets.Struct, AllowMultiple = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class InlineArrayAttribute : Attribute
{
public int Length { get; }
public InlineArrayAttribute(int length)
{
Length = length;
}
}
}
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;
}
}
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class ObsoletedOSPlatformAttribute : Attribute
{
public string? Message { get; }
public string? Url { get; set; }
public ObsoletedOSPlatformAttribute(string platformName)
{
}
public ObsoletedOSPlatformAttribute(string platformName, string? message)
{
Message = message;
}
}
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class SupportedOSPlatformAttribute : Attribute
{
public SupportedOSPlatformAttribute(string platformName)
{
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class SupportedOSPlatformGuardAttribute : Attribute
{
public SupportedOSPlatformGuardAttribute(string platformName)
{
}
}
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class TargetPlatformAttribute : Attribute
{
public TargetPlatformAttribute(string platformName)
{
}
}
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface, AllowMultiple = true, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class UnsupportedOSPlatformAttribute : Attribute
{
public string? Message { get; }
public UnsupportedOSPlatformAttribute(string platformName)
{
}
public UnsupportedOSPlatformAttribute(string platformName, string? message)
{
Message = message;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class UnsupportedOSPlatformGuardAttribute : Attribute
{
public UnsupportedOSPlatformGuardAttribute(string platformName)
{
}
}
}
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.Constructor | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class OverloadResolutionPriorityAttribute : Attribute
{
public int Priority { get; }
public OverloadResolutionPriorityAttribute(int priority)
{
Priority = priority;
}
}
[AttributeUsage(AttributeTargets.Parameter, Inherited = true, AllowMultiple = false)]
[ExcludeFromCodeCoverage]
internal sealed class ParamCollectionAttribute : 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
{
}
[AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class DisableRuntimeMarshallingAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class UnsafeAccessorAttribute : Attribute
{
public UnsafeAccessorKind Kind { get; }
public string? Name { get; set; }
public UnsafeAccessorAttribute(UnsafeAccessorKind kind)
{
Kind = kind;
}
}
internal enum UnsafeAccessorKind
{
Constructor,
Method,
StaticMethod,
Field,
StaticField
}
}
namespace System.Diagnostics
{
[AttributeUsage(AttributeTargets.Method)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class DebuggerDisableUserUnhandledExceptionsAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class StackTraceHiddenAttribute : Attribute
{
}
}
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class AllowNullAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class ConstantExpectedAttribute : Attribute
{
public object? Min { get; set; }
public object? Max { get; set; }
}
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class DisallowNullAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class DoesNotReturnAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class DoesNotReturnIfAttribute : Attribute
{
public bool ParameterValue { get; }
public DoesNotReturnIfAttribute(bool parameterValue)
{
ParameterValue = parameterValue;
}
}
[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.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class MaybeNullAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class MaybeNullWhenAttribute : Attribute
{
public bool ReturnValue { get; }
public MaybeNullWhenAttribute(bool returnValue)
{
ReturnValue = returnValue;
}
}
[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.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class NotNullAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class NotNullIfNotNullAttribute : Attribute
{
public string ParameterName { get; }
public NotNullIfNotNullAttribute(string parameterName)
{
ParameterName = parameterName;
}
}
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class NotNullWhenAttribute : Attribute
{
public bool ReturnValue { get; }
public NotNullWhenAttribute(bool returnValue)
{
ReturnValue = returnValue;
}
}
[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
{
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class DynamicallyAccessedMembersAttribute : Attribute
{
public DynamicallyAccessedMemberTypes MemberTypes { get; }
public DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes memberTypes)
{
MemberTypes = memberTypes;
}
}
[Flags]
internal enum DynamicallyAccessedMemberTypes
{
None = 0,
PublicParameterlessConstructor = 1,
PublicConstructors = 3,
NonPublicConstructors = 4,
PublicMethods = 8,
NonPublicMethods = 0x10,
PublicFields = 0x20,
NonPublicFields = 0x40,
PublicNestedTypes = 0x80,
NonPublicNestedTypes = 0x100,
PublicProperties = 0x200,
NonPublicProperties = 0x400,
PublicEvents = 0x800,
NonPublicEvents = 0x1000,
Interfaces = 0x2000,
All = -1
}
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class DynamicDependencyAttribute : Attribute
{
public string? MemberSignature { get; }
public DynamicallyAccessedMemberTypes MemberTypes { get; }
public Type? Type { get; }
public string? TypeName { get; }
public string? AssemblyName { get; }
public string? Condition { get; set; }
public DynamicDependencyAttribute(string memberSignature)
{
MemberSignature = memberSignature;
}
public DynamicDependencyAttribute(string memberSignature, Type type)
{
MemberSignature = memberSignature;
Type = type;
}
public DynamicDependencyAttribute(string memberSignature, string typeName, string assemblyName)
{
MemberSignature = memberSignature;
TypeName = typeName;
AssemblyName = assemblyName;
}
public DynamicDependencyAttribute(DynamicallyAccessedMemberTypes memberTypes, Type type)
{
MemberTypes = memberTypes;
Type = type;
}
public DynamicDependencyAttribute(DynamicallyAccessedMemberTypes memberTypes, string typeName, string assemblyName)
{
MemberTypes = memberTypes;
TypeName = typeName;
AssemblyName = assemblyName;
}
}
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class FeatureGuardAttribute : Attribute
{
public Type FeatureType { get; }
public FeatureGuardAttribute(Type featureType)
{
FeatureType = featureType;
}
}
[AttributeUsage(AttributeTargets.Property, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class FeatureSwitchDefinitionAttribute : Attribute
{
public string SwitchName { get; }
public FeatureSwitchDefinitionAttribute(string switchName)
{
SwitchName = switchName;
}
}
[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event, Inherited = false, AllowMultiple = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class RequiresAssemblyFilesAttribute : Attribute
{
public string? Message { get; }
public string? Url { get; set; }
public RequiresAssemblyFilesAttribute()
{
}
public RequiresAssemblyFilesAttribute(string message)
{
Message = message;
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Method, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class RequiresDynamicCodeAttribute : Attribute
{
public string Message { get; }
public string? Url { get; set; }
public RequiresDynamicCodeAttribute(string message)
{
Message = message;
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Constructor | AttributeTargets.Method, Inherited = false)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class RequiresUnreferencedCodeAttribute : Attribute
{
public string Message { get; }
public string? Url { get; set; }
public RequiresUnreferencedCodeAttribute(string message)
{
Message = message;
}
}
[AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
[Conditional("MULTI_TARGETING_SUPPORT_ATTRIBUTES")]
internal sealed class UnconditionalSuppressMessageAttribute : Attribute
{
public string Category { get; }
public string CheckId { get; }
public string? Scope { get; set; }
public string? Target { get; set; }
public string? MessageId { get; set; }
public string? Justification { get; set; }
public UnconditionalSuppressMessageAttribute(string category, string checkId)
{
Category = category;
CheckId = checkId;
}
}
}
namespace JetBrains.Annotations
{
[AttributeUsage(AttributeTargets.Parameter)]
internal sealed class NoEnumerationAttribute : Attribute
{
}
}
namespace Serilog
{
public interface ILogger
{
ILogger ForContext(ILogEventEnricher enricher);
ILogger ForContext(IEnumerable<ILogEventEnricher> enrichers);
ILogger ForContext(string propertyName, object? value, bool destructureObjects = false);
ILogger ForContext<TSource>();
ILogger ForContext(Type source);
void Write(LogEvent logEvent);
[MessageTemplateFormatMethod("messageTemplate")]
void Write(LogEventLevel level, string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Write<T>(LogEventLevel level, string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Write<T0, T1>(LogEventLevel level, string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Write<T0, T1, T2>(LogEventLevel level, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Write(LogEventLevel level, string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
void Write(LogEventLevel level, Exception? exception, string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Write<T>(LogEventLevel level, Exception? exception, string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Write<T0, T1>(LogEventLevel level, Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Write<T0, T1, T2>(LogEventLevel level, Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Write(LogEventLevel level, Exception? exception, string messageTemplate, params object?[]? propertyValues);
bool IsEnabled(LogEventLevel level);
[MessageTemplateFormatMethod("messageTemplate")]
void Verbose(string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Verbose<T>(string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Verbose<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Verbose<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Verbose(string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
void Verbose(Exception? exception, string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Verbose<T>(Exception? exception, string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Verbose<T0, T1>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Verbose<T0, T1, T2>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Verbose(Exception? exception, string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
void Debug(string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Debug<T>(string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Debug<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Debug<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Debug(string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
void Debug(Exception? exception, string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Debug<T>(Exception? exception, string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Debug<T0, T1>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Debug<T0, T1, T2>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Debug(Exception? exception, string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
void Information(string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Information<T>(string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Information<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Information<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Information(string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
void Information(Exception? exception, string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Information<T>(Exception? exception, string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Information<T0, T1>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Information<T0, T1, T2>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Information(Exception? exception, string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
void Warning(string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Warning<T>(string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Warning<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Warning<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Warning(string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
void Warning(Exception? exception, string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Warning<T>(Exception? exception, string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Warning<T0, T1>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Warning<T0, T1, T2>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Warning(Exception? exception, string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
void Error(string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Error<T>(string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Error<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Error<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Error(string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
void Error(Exception? exception, string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Error<T>(Exception? exception, string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Error<T0, T1>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Error<T0, T1, T2>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Error(Exception? exception, string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
void Fatal(string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Fatal<T>(string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Fatal<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Fatal<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Fatal(string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
void Fatal(Exception? exception, string messageTemplate);
[MessageTemplateFormatMethod("messageTemplate")]
void Fatal<T>(Exception? exception, string messageTemplate, T propertyValue);
[MessageTemplateFormatMethod("messageTemplate")]
void Fatal<T0, T1>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1);
[MessageTemplateFormatMethod("messageTemplate")]
void Fatal<T0, T1, T2>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2);
[MessageTemplateFormatMethod("messageTemplate")]
void Fatal(Exception? exception, string messageTemplate, params object?[]? propertyValues);
[MessageTemplateFormatMethod("messageTemplate")]
bool BindMessageTemplate(string messageTemplate, object?[]? propertyValues, [NotNullWhen(true)] out MessageTemplate? parsedTemplate, [NotNullWhen(true)] out IEnumerable<LogEventProperty>? boundProperties);
bool BindProperty(string? propertyName, object? value, bool destructureObjects, [NotNullWhen(true)] out LogEventProperty? property);
}
public static class Log
{
private static ILogger _logger = Serilog.Core.Logger.None;
public static ILogger Logger
{
get
{
return _logger;
}
set
{
_logger = Guard.AgainstNull(value, "value");
}
}
public static void CloseAndFlush()
{
(Interlocked.Exchange(ref _logger, Serilog.Core.Logger.None) as IDisposable)?.Dispose();
}
public static ILogger ForContext(ILogEventEnricher enricher)
{
return Logger.ForContext(enricher);
}
public static ILogger ForContext(ILogEventEnricher[] enrichers)
{
return Logger.ForContext(enrichers);
}
public static ILogger ForContext(string propertyName, object? value, bool destructureObjects = false)
{
return Logger.ForContext(propertyName, value, destructureObjects);
}
public static ILogger ForContext<TSource>()
{
return Logger.ForContext<TSource>();
}
public static ILogger ForContext(Type source)
{
return Logger.ForContext(source);
}
public static void Write(LogEvent logEvent)
{
Logger.Write(logEvent);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Write(LogEventLevel level, string messageTemplate)
{
Logger.Write(level, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Write<T>(LogEventLevel level, string messageTemplate, T propertyValue)
{
Logger.Write(level, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Write<T0, T1>(LogEventLevel level, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Logger.Write(level, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Write<T0, T1, T2>(LogEventLevel level, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Logger.Write(level, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Write(LogEventLevel level, string messageTemplate, params object?[]? propertyValues)
{
Logger.Write(level, messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Write(LogEventLevel level, Exception? exception, string messageTemplate)
{
Logger.Write(level, exception, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Write<T>(LogEventLevel level, Exception? exception, string messageTemplate, T propertyValue)
{
Logger.Write(level, exception, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Write<T0, T1>(LogEventLevel level, Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Logger.Write(level, exception, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Write<T0, T1, T2>(LogEventLevel level, Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Logger.Write(level, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Write(LogEventLevel level, Exception? exception, string messageTemplate, params object?[]? propertyValues)
{
Logger.Write(level, exception, messageTemplate, propertyValues);
}
public static bool IsEnabled(LogEventLevel level)
{
return Logger.IsEnabled(level);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Verbose(string messageTemplate)
{
Write(LogEventLevel.Verbose, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Verbose<T>(string messageTemplate, T propertyValue)
{
Write(LogEventLevel.Verbose, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Verbose<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Write(LogEventLevel.Verbose, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Verbose<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Write(LogEventLevel.Verbose, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Verbose(string messageTemplate, params object?[]? propertyValues)
{
Logger.Verbose(messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Verbose(Exception? exception, string messageTemplate)
{
Write(LogEventLevel.Verbose, exception, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Verbose<T>(Exception? exception, string messageTemplate, T propertyValue)
{
Write(LogEventLevel.Verbose, exception, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Verbose<T0, T1>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Write(LogEventLevel.Verbose, exception, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Verbose<T0, T1, T2>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Write(LogEventLevel.Verbose, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Verbose(Exception? exception, string messageTemplate, params object?[]? propertyValues)
{
Logger.Verbose(exception, messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Debug(string messageTemplate)
{
Write(LogEventLevel.Debug, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Debug<T>(string messageTemplate, T propertyValue)
{
Write(LogEventLevel.Debug, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Debug<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Write(LogEventLevel.Debug, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Debug<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Write(LogEventLevel.Debug, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Debug(string messageTemplate, params object?[]? propertyValues)
{
Logger.Debug(messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Debug(Exception? exception, string messageTemplate)
{
Write(LogEventLevel.Debug, exception, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Debug<T>(Exception? exception, string messageTemplate, T propertyValue)
{
Write(LogEventLevel.Debug, exception, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Debug<T0, T1>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Write(LogEventLevel.Debug, exception, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Debug<T0, T1, T2>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Write(LogEventLevel.Debug, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Debug(Exception? exception, string messageTemplate, params object?[]? propertyValues)
{
Logger.Debug(exception, messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Information(string messageTemplate)
{
Write(LogEventLevel.Information, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Information<T>(string messageTemplate, T propertyValue)
{
Write(LogEventLevel.Information, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Information<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Write(LogEventLevel.Information, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Information<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Write(LogEventLevel.Information, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Information(string messageTemplate, params object?[]? propertyValues)
{
Logger.Information(messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Information(Exception? exception, string messageTemplate)
{
Write(LogEventLevel.Information, exception, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Information<T>(Exception? exception, string messageTemplate, T propertyValue)
{
Write(LogEventLevel.Information, exception, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Information<T0, T1>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Write(LogEventLevel.Information, exception, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Information<T0, T1, T2>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Write(LogEventLevel.Information, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Information(Exception? exception, string messageTemplate, params object?[]? propertyValues)
{
Logger.Information(exception, messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Warning(string messageTemplate)
{
Write(LogEventLevel.Warning, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Warning<T>(string messageTemplate, T propertyValue)
{
Write(LogEventLevel.Warning, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Warning<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Write(LogEventLevel.Warning, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Warning<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Write(LogEventLevel.Warning, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Warning(string messageTemplate, params object?[]? propertyValues)
{
Logger.Warning(messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Warning(Exception? exception, string messageTemplate)
{
Write(LogEventLevel.Warning, exception, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Warning<T>(Exception? exception, string messageTemplate, T propertyValue)
{
Write(LogEventLevel.Warning, exception, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Warning<T0, T1>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Write(LogEventLevel.Warning, exception, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Warning<T0, T1, T2>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Write(LogEventLevel.Warning, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Warning(Exception? exception, string messageTemplate, params object?[]? propertyValues)
{
Logger.Warning(exception, messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Error(string messageTemplate)
{
Write(LogEventLevel.Error, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Error<T>(string messageTemplate, T propertyValue)
{
Write(LogEventLevel.Error, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Error<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Write(LogEventLevel.Error, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Error<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Write(LogEventLevel.Error, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Error(string messageTemplate, params object?[]? propertyValues)
{
Logger.Error(messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Error(Exception? exception, string messageTemplate)
{
Write(LogEventLevel.Error, exception, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Error<T>(Exception? exception, string messageTemplate, T propertyValue)
{
Write(LogEventLevel.Error, exception, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Error<T0, T1>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Write(LogEventLevel.Error, exception, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Error<T0, T1, T2>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Write(LogEventLevel.Error, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Error(Exception? exception, string messageTemplate, params object?[]? propertyValues)
{
Logger.Error(exception, messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Fatal(string messageTemplate)
{
Write(LogEventLevel.Fatal, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Fatal<T>(string messageTemplate, T propertyValue)
{
Write(LogEventLevel.Fatal, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Fatal<T0, T1>(string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Write(LogEventLevel.Fatal, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Fatal<T0, T1, T2>(string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Write(LogEventLevel.Fatal, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Fatal(string messageTemplate, params object?[]? propertyValues)
{
Logger.Fatal(messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Fatal(Exception? exception, string messageTemplate)
{
Write(LogEventLevel.Fatal, exception, messageTemplate);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Fatal<T>(Exception? exception, string messageTemplate, T propertyValue)
{
Write(LogEventLevel.Fatal, exception, messageTemplate, propertyValue);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Fatal<T0, T1>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1)
{
Write(LogEventLevel.Fatal, exception, messageTemplate, propertyValue0, propertyValue1);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Fatal<T0, T1, T2>(Exception? exception, string messageTemplate, T0 propertyValue0, T1 propertyValue1, T2 propertyValue2)
{
Write(LogEventLevel.Fatal, exception, messageTemplate, propertyValue0, propertyValue1, propertyValue2);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static void Fatal(Exception? exception, string messageTemplate, params object?[]? propertyValues)
{
Logger.Fatal(exception, messageTemplate, propertyValues);
}
[MessageTemplateFormatMethod("messageTemplate")]
public static bool BindMessageTemplate(string messageTemplate, object?[] propertyValues, [NotNullWhen(true)] out MessageTemplate? parsedTemplate, [NotNullWhen(true)] out IEnumerable<LogEventProperty>? boundProperties)
{
return Logger.BindMessageTemplate(messageTemplate, propertyValues, out parsedTemplate, out boundProperties);
}
public static bool BindProperty(string propertyName, object? value, bool destructureObjects, [NotNullWhen(true)] out LogEventProperty? property)
{
return Logger.BindProperty(propertyName, value, destructureObjects, out property);
}
}
public class LoggerConfiguration
{
private readonly List<ILogEventSink> _logEventSinks = new List<ILogEventSink>();
private readonly List<ILogEventSink> _auditSinks = new List<ILogEventSink>();
private readonly List<ILogEventEnricher> _enrichers = new List<ILogEventEnricher>();
private readonly List<ILogEventFilter> _filters = new List<ILogEventFilter>();
private readonly List<Type> _additionalScalarTypes = new List<Type>();
private readonly HashSet<Type> _additionalDictionaryTypes = new HashSet<Type>();
private readonly List<IDestructuringPolicy> _additionalDestructuringPolicies = new List<IDestructuringPolicy>();
private readonly Dictionary<string, LoggingLevelSwitch> _overrides = new Dictionary<string, LoggingLevelSwitch>();
private LogEventLevel _minimumLevel = LogEventLevel.Information;
private LoggingLevelSwitch? _levelSwitch;
private int _maximumDestructuringDepth = 10;
private int _maximumStringLength = int.MaxValue;
private int _maximumCollectionCount = int.MaxValue;
private bool _loggerCreated;
public LoggerSinkConfiguration WriteTo { get; internal set; }
public LoggerAuditSinkConfiguration AuditTo => new LoggerAuditSinkConfiguration(this, delegate(ILogEventSink s)
{
_auditSinks.Add(s);
});
public LoggerMinimumLevelConfiguration MinimumLevel => new LoggerMinimumLevelConfiguration(this, delegate(LogEventLevel l)
{
_minimumLevel = l;
_levelSwitch = null;
}, delegate(LoggingLevelSwitch sw)
{
_levelSwitch = sw;
}, delegate(string s, LoggingLevelSwitch lls)
{
_overrides[s] = lls;
});
public LoggerEnrichmentConfiguration Enrich { get; internal set; }
public LoggerFilterConfiguration Filter => new LoggerFilterConfiguration(this, delegate(ILogEventFilter f)
{
_filters.Add(f);
});
public LoggerDestructuringConfiguration Destructure => new LoggerDestructuringConfiguration(this, _additionalScalarTypes.Add, delegate(Type type)
{
_additionalDictionaryTypes.Add(type);
}, _additionalDestructuringPolicies.Add, delegate(int depth)
{
_maximumDestructuringDepth = depth;
}, delegate(int length)
{
_maximumStringLength = length;
}, delegate(int count)
{
_maximumCollectionCount = count;
});
public LoggerSettingsConfiguration ReadFrom => new LoggerSettingsConfiguration(this);
public LoggerConfiguration()
{
WriteTo = new LoggerSinkConfiguration(this, delegate(ILogEventSink s)
{
_logEventSinks.Add(s);
});
Enrich = new LoggerEnrichmentConfiguration(this, delegate(ILogEventEnricher e)
{
_enrichers.Add(e);
});
}
public Logger CreateLogger()
{
if (_loggerCreated)
{
throw new InvalidOperationException("CreateLogger() was previously called and can only be called once.");
}
_loggerCreated = true;
ILogEventSink logEventSink = null;
if (_logEventSinks.Count > 0)
{
logEventSink = new SafeAggregateSink(_logEventSinks);
}
bool flag = _auditSinks.Any();
if (flag)
{
IEnumerable<ILogEventSink> sinks;
if (logEventSink != null)
{
sinks = new ILogEventSink[1] { logEventSink }.Concat(_auditSinks);
}
else
{
IEnumerable<ILogEventSink> auditSinks = _auditSinks;
sinks = auditSinks;
}
logEventSink = new AggregateSink(sinks);
}
if (logEventSink == null)
{
logEventSink = new SafeAggregateSink(Array.Empty<ILogEventSink>());
}
if (_filters.Any())
{
logEventSink = new FilteringSink(logEventSink, _filters, flag);
}
MessageTemplateProcessor messageTemplateProcessor = new MessageTemplateProcessor(new PropertyValueConverter(_maximumDestructuringDepth, _maximumStringLength, _maximumCollectionCount, _additionalScalarTypes, _additionalDictionaryTypes, _additionalDestructuringPolicies, flag));
ILogEventEnricher enricher = _enrichers.Count switch
{
0 => new EmptyEnricher(),
1 => _enrichers[0],
_ => new SafeAggregateEnricher(_enrichers),
};
LevelOverrideMap overrideMap = null;
if (_overrides.Count != 0)
{
overrideMap = new LevelOverrideMap(_overrides, _minimumLevel, _levelSwitch);
}
ILogEventSink[] disposableSinks = (from s in _logEventSinks.Concat(_auditSinks)
where s is IDisposable
select s).ToArray();
return new Logger(messageTemplateProcessor, (_levelSwitch == null) ? _minimumLevel : LogEventLevel.Verbose, _levelSwitch, logEventSink, enricher, Dispose, overrideMap);
void Dispose()
{
ILogEventSink[] array = disposableSinks;
for (int i = 0; i < array.Length; i++)
{
(array[i] as IDisposable)?.Dispose();
}
}
}
}
public static class LoggerExtensions
{
public static ILogger ForContext<TValue>(this ILogger logger, LogEventLevel level, string propertyName, TValue value, bool destructureObjects = false)
{
Guard.AgainstNull(logger, "logger");
if (!logger.IsEnabled(level))
{
return logger;
}
return logger.ForContext(propertyName, value, destructureObjects);
}
}
}
namespace Serilog.Settings.KeyValuePairs
{
internal static class CallableConfigurationMethodFinder
{
internal static IList<MethodInfo> FindConfigurationMethods(IEnumerable<Assembly> configurationAssemblies, Type configType)
{
Type configType2 = configType;
List<MethodInfo> list = (from m in configurationAssemblies.SelectMany((Assembly a) => a.ExportedTypes.Where((Type t) => t.IsSealed && t.IsAbstract && !t.IsNested)).SelectMany((Type t) => t.GetMethods(BindingFlags.Static | BindingFlags.Public))
where m.IsDefined(typeof(ExtensionAttribute), inherit: false) && m.GetParameters()[0].ParameterType == configType2
select m).ToList();
if (configType2 == typeof(LoggerSinkConfiguration))
{
list.AddRange(SurrogateConfigurationMethods.WriteTo);
}
if (configType2 == typeof(LoggerAuditSinkConfiguration))
{
list.AddRange(SurrogateConfigurationMethods.AuditTo);
}
if (configType2 == typeof(LoggerEnrichmentConfiguration))
{
list.AddRange(SurrogateConfigurationMethods.Enrich);
}
if (configType2 == typeof(LoggerDestructuringConfiguration))
{
list.AddRange(SurrogateConfigurationMethods.Destructure);
}
if (configType2 == typeof(LoggerFilterConfiguration))
{
list.AddRange(SurrogateConfigurationMethods.Filter);
}
return list;
}
}
internal class KeyValuePairSettings : ILoggerSettings
{
internal class ConfigurationMethodCall
{
public string MethodName { get; }
public string ArgumentName { get; }
public string Value { get; }
public ConfigurationMethodCall(string methodName, string argumentName, string value)
{
MethodName = methodName;
ArgumentName = argumentName;
Value = value;
}
}
private const string UsingDirective = "using";
private const string LevelSwitchDirective = "level-switch";
private const string AuditToDirective = "audit-to";
private const string WriteToDirective = "write-to";
private const string MinimumLevelDirective = "minimum-level";
private const string MinimumLevelControlledByDirective = "minimum-level:controlled-by";
private const string EnrichWithDirective = "enrich";
private const string EnrichWithPropertyDirective = "enrich:with-property";
private const string FilterDirective = "filter";
private const string DestructureDirective = "destructure";
private const string UsingDirectiveFullFormPrefix = "using:";
private const string EnrichWithPropertyDirectivePrefix = "enrich:with-property:";
private const string MinimumLevelOverrideDirectivePrefix = "minimum-level:override:";
private const string CallableDirectiveRegex = "^(?<directive>audit-to|write-to|enrich|filter|destructure):(?<method>[A-Za-z0-9]*)(\\.(?<argument>[A-Za-z0-9]*)){0,1}$";
private const string LevelSwitchDeclarationDirectiveRegex = "^level-switch:(?<switchName>.*)$";
private const string LevelSwitchNameRegex = "^\\$[A-Za-z]+[A-Za-z0-9]*$";
private static readonly string[] _supportedDirectives = new string[10] { "using", "level-switch", "audit-to", "write-to", "minimum-level", "minimum-level:controlled-by", "enrich:with-property", "enrich", "filter", "destructure" };
private static readonly Dictionary<string, Type> CallableDirectiveReceiverTypes = new Dictionary<string, Type>
{
["audit-to"] = typeof(LoggerAuditSinkConfiguration),
["write-to"] = typeof(LoggerSinkConfiguration),
["enrich"] = typeof(LoggerEnrichmentConfiguration),
["filter"] = typeof(LoggerFilterConfiguration),
["destructure"] = typeof(LoggerDestructuringConfiguration)
};
private static readonly Dictionary<Type, Func<LoggerConfiguration, object>> CallableDirectiveReceivers = new Dictionary<Type, Func<LoggerConfiguration, object>>
{
[typeof(LoggerAuditSinkConfiguration)] = (LoggerConfiguration lc) => lc.AuditTo,
[typeof(LoggerSinkConfiguration)] = (LoggerConfiguration lc) => lc.WriteTo,
[typeof(LoggerEnrichmentConfiguration)] = (LoggerConfiguration lc) => lc.Enrich,
[typeof(LoggerFilterConfiguration)] = (LoggerConfiguration lc) => lc.Filter,
[typeof(LoggerDestructuringConfiguration)] = (LoggerConfiguration lc) => lc.Destructure
};
private readonly IReadOnlyDictionary<string, string> _settings;
public KeyValuePairSettings(IReadOnlyDictionary<string, string> settings)
{
_settings = Guard.AgainstNull(settings, "settings");
}
public void Configure(LoggerConfiguration loggerConfiguration)
{
Guard.AgainstNull(loggerConfiguration, "loggerConfiguration");
Dictionary<string, string> dictionary = _settings.Where<KeyValuePair<string, string>>((KeyValuePair<string, string> kvp) => _supportedDirectives.Any(kvp.Key.StartsWith)).ToDictionary((KeyValuePair<string, string> kvp) => kvp.Key, (KeyValuePair<string, string> kvp) => kvp.Value);
IReadOnlyDictionary<string, LoggingLevelSwitch> readOnlyDictionary = ParseNamedLevelSwitchDeclarationDirectives(dictionary);
if (dictionary.TryGetValue("minimum-level", out var value) && Enum.TryParse<LogEventLevel>(value, out var result))
{
loggerConfiguration.MinimumLevel.Is(result);
}
foreach (KeyValuePair<string, string> item in dictionary.Where((KeyValuePair<string, string> dir) => dir.Key.StartsWith("enrich:with-property:") && dir.Key.Length > "enrich:with-property:".Length))
{
string name = item.Key.Substring("enrich:with-property:".Length);
loggerConfiguration.Enrich.WithProperty(name, item.Value);
}
if (dictionary.TryGetValue("minimum-level:controlled-by", out var value2))
{
LoggingLevelSwitch levelSwitch = LookUpSwitchByName(value2, readOnlyDictionary);
loggerConfiguration.MinimumLevel.ControlledBy(levelSwitch);
}
foreach (KeyValuePair<string, string> item2 in dictionary.Where((KeyValuePair<string, string> dir) => dir.Key.StartsWith("minimum-level:override:") && dir.Key.Length > "minimum-level:override:".Length))
{
string source = item2.Key.Substring("minimum-level:override:".Length);
if (Enum.TryParse<LogEventLevel>(item2.Value, out var result2))
{
loggerConfiguration.MinimumLevel.Override(source, result2);
continue;
}
LoggingLevelSwitch levelSwitch2 = LookUpSwitchByName(item2.Value, readOnlyDictionary);
loggerConfiguration.MinimumLevel.Override(source, levelSwitch2);
}
Regex matchCallables = new Regex("^(?<directive>audit-to|write-to|enrich|filter|destructure):(?<method>[A-Za-z0-9]*)(\\.(?<argument>[A-Za-z0-9]*)){0,1}$");
var source2 = (from <>h__TransparentIdentifier0 in dictionary.Where(delegate(KeyValuePair<string, string> wt)
{
Regex regex2 = matchCallables;
KeyValuePair<string, string> keyValuePair2 = wt;
return regex2.IsMatch(keyValuePair2.Key);
}).Select(delegate(KeyValuePair<string, string> wt)
{
Regex regex = matchCallables;
KeyValuePair<string, string> keyValuePair = wt;
return new
{
wt = wt,
match = regex.Match(keyValuePair.Key)
};
})
select new
{
ReceiverType = CallableDirectiveReceiverTypes[<>h__TransparentIdentifier0.match.Groups["directive"].Value],
Call = new ConfigurationMethodCall(<>h__TransparentIdentifier0.match.Groups["method"].Value, <>h__TransparentIdentifier0.match.Groups["argument"].Value, <>h__TransparentIdentifier0.wt.Value)
}).ToList();
if (!source2.Any())
{
return;
}
List<Assembly> configurationAssemblies = LoadConfigurationAssemblies(dictionary).ToList();
foreach (var item3 in from d in source2
group d by d.ReceiverType)
{
IList<MethodInfo> configurationMethods = CallableConfigurationMethodFinder.FindConfigurationMethods(configurationAssemblies, item3.Key);
ApplyDirectives((from d in item3
select d.Call into call
group call by call.MethodName).ToList(), configurationMethods, CallableDirectiveReceivers[item3.Key](loggerConfiguration), readOnlyDictionary);
}
}
internal static bool IsValidSwitchName(string input)
{
return Regex.IsMatch(input, "^\\$[A-Za-z]+[A-Za-z0-9]*$");
}
private static IReadOnlyDictionary<string, LoggingLevelSwitch> ParseNamedLevelSwitchDeclarationDirectives(IReadOnlyDictionary<string, string> directives)
{
Regex matchLevelSwitchDeclarations = new Regex("^level-switch:(?<switchName>.*)$");
var list = (from <>h__TransparentIdentifier0 in directives.Where<KeyValuePair<string, string>>(delegate(KeyValuePair<string, string> wt)
{
Regex regex2 = matchLevelSwitchDeclarations;
KeyValuePair<string, string> keyValuePair2 = wt;
return regex2.IsMatch(keyValuePair2.Key);
}).Select(delegate(KeyValuePair<string, string> wt)
{
Regex regex = matchLevelSwitchDeclarations;
KeyValuePair<string, string> keyValuePair = wt;
return new
{
wt = wt,
match = regex.Match(keyValuePair.Key)
};
})
select new
{
SwitchName = <>h__TransparentIdentifier0.match.Groups["switchName"].Value,
InitialSwitchLevel = <>h__TransparentIdentifier0.wt.Value
}).ToList();
Dictionary<string, LoggingLevelSwitch> dictionary = new Dictionary<string, LoggingLevelSwitch>();
foreach (var item in list)
{
string switchName = item.SwitchName;
string initialSwitchLevel = item.InitialSwitchLevel;
if (!IsValidSwitchName(switchName))
{
throw new FormatException("\"" + switchName + "\" is not a valid name for a Level Switch declaration. Level switch must be declared with a '$' sign, like \"level-switch:$switchName\"");
}
LoggingLevelSwitch value = ((!(initialSwitchLevel == string.Empty)) ? new LoggingLevelSwitch((LogEventLevel)Enum.Parse(typeof(LogEventLevel), initialSwitchLevel)) : new LoggingLevelSwitch());
dictionary.Add(switchName, value);
}
return dictionary;
}
private static LoggingLevelSwitch LookUpSwitchByName(string switchName, IReadOnlyDictionary<string, LoggingLevelSwitch> declaredLevelSwitches)
{
if (declaredLevelSwitches.TryGetValue(switchName, out LoggingLevelSwitch value))
{
return value;
}
throw new InvalidOperationException("No LoggingLevelSwitch has been declared with name \"" + switchName + "\". You might be missing a key \"level-switch:" + switchName + "\"");
}
private static object ConvertOrLookupByName(string valueOrSwitchName, Type type, IReadOnlyDictionary<string, LoggingLevelSwitch> declaredSwitches)
{
if (type == typeof(LoggingLevelSwitch))
{
return LookUpSwitchByName(valueOrSwitchName, declaredSwitches);
}
return SettingValueConversions.ConvertToType(valueOrSwitchName, type);
}
private static void ApplyDirectives(List<IGrouping<string, ConfigurationMethodCall>> directives, IList<MethodInfo> configurationMethods, object loggerConfigMethod, IReadOnlyDictionary<string, LoggingLevelSwitch> declaredSwitches)
{
IReadOnlyDictionary<string, LoggingLevelSwitch> declaredSwitches2 = declaredSwitches;
foreach (IGrouping<string, ConfigurationMethodCall> directiveInfo in directives)
{
MethodInfo methodInfo = SelectConfigurationMethod(configurationMethods, directiveInfo.Key, directiveInfo);
if (methodInfo == null)
{
SelfLog.WriteLine("Setting \"{0}\" could not be matched to an implementation in any of the loaded assemblies. To use settings from additional assemblies, specify them with the \"serilog:using\" key.", directiveInfo.Key);
continue;
}
List<object> list = (from p in methodInfo.GetParameters().Skip(1)
let directive = directiveInfo.FirstOrDefault((ConfigurationMethodCall s) => s.ArgumentName == p.Name)
select SuppressConvertCall(directive, p)).ToList();
list.Insert(0, loggerConfigMethod);
methodInfo.Invoke(null, list.ToArray());
}
object? SuppressConvertCall(ConfigurationMethodCall? directive, ParameterInfo p)
{
if (directive != null)
{
return ConvertOrLookupByName(directive.Value, p.ParameterType, declaredSwitches2);
}
return p.DefaultValue;
}
}
internal static MethodInfo? SelectConfigurationMethod(IEnumerable<MethodInfo> candidateMethods, string name, IEnumerable<ConfigurationMethodCall> suppliedArgumentValues)
{
string name2 = name;
IEnumerable<ConfigurationMethodCall> suppliedArgumentValues2 = suppliedArgumentValues;
return (from m in candidateMethods
where m.Name == name2 && m.GetParameters().Skip(1).All((ParameterInfo p) => p.HasDefaultValue || suppliedArgumentValues2.Any((ConfigurationMethodCall s) => s.ArgumentName == p.Name))
orderby m.GetParameters().Count((ParameterInfo p) => suppliedArgumentValues2.Any((ConfigurationMethodCall s) => s.ArgumentName == p.Name)) descending
select m).FirstOrDefault();
}
internal static IEnumerable<Assembly> LoadConfigurationAssemblies(IReadOnlyDictionary<string, string> directives)
{
List<Assembly> list = new List<Assembly> { typeof(ILogger).Assembly };
foreach (KeyValuePair<string, string> item in directives.Where<KeyValuePair<string, string>>((KeyValuePair<string, string> d) => d.Key.Equals("using") || d.Key.StartsWith("using:")))
{
if (string.IsNullOrWhiteSpace(item.Value))
{
throw new InvalidOperationException("A zero-length or whitespace assembly name was supplied to a serilog:using configuration statement.");
}
AssemblyName assemblyRef = new AssemblyName(item.Value);
list.Add(Assembly.Load(assemblyRef));
}
return list.Distinct();
}
}
internal class SettingValueConversions
{
private static Regex StaticMemberAccessorRegex = new Regex("^(?<shortTypeName>[^:]+)::(?<memberName>[A-Za-z][A-Za-z0-9]*)(?<typeNameExtraQualifiers>[^:]*)$");
private static Dictionary<Type, Func<string, object>> ExtendedTypeConversions = new Dictionary<Type, Func<string, object>>
{
{
typeof(Uri),
(string s) => new Uri(s)
},
{
typeof(TimeSpan),
(string s) => TimeSpan.Parse(s)
},
{
typeof(Type),
(string s) => Type.GetType(s, throwOnError: true)
}
};
public static object? ConvertToType(string value, Type toType)
{
Type toType2 = toType;
if (toType2.IsGenericType && toType2.GetGenericTypeDefinition() == typeof(Nullable<>))
{
if (value == string.Empty)
{
return null;
}
toType2 = toType2.GenericTypeArguments[0];
}
if (toType2.IsEnum)
{
return Enum.Parse(toType2, value);
}
Func<string, object> func = (from t in ExtendedTypeConversions
where t.Key.IsAssignableFrom(toType2)
select t.Value).FirstOrDefault();
if (func != null)
{
return func(value);
}
if ((toType2.IsInterface || toType2.IsAbstract) && !string.IsNullOrWhiteSpace(value))
{
if (TryParseStaticMemberAccessor(value, out string accessorTypeName, out string memberName))
{
Type type = Type.GetType(accessorTypeName, throwOnError: true);
PropertyInfo propertyInfo = type.GetProperties(BindingFlags.Static | BindingFlags.Public).FirstOrDefault((PropertyInfo x) => x.Name == memberName && x.GetMethod != null);
if (propertyInfo != null)
{
return propertyInfo.GetValue(null);
}
FieldInfo fieldInfo = type.GetFields(BindingFlags.Static | BindingFlags.Public).FirstOrDefault((FieldInfo x) => x.Name == memberName);
if (fieldInfo != null)
{
return fieldInfo.GetValue(null);
}
throw new InvalidOperationException("Could not find a public static property or field with name `" + memberName + "` on type `" + accessorTypeName + "`");
}
Type type2 = Type.GetType(value.Trim(), throwOnError: false);
if (type2 != null)
{
ConstructorInfo? constructorInfo = type2.GetConstructors(BindingFlags.Instance | BindingFlags.Public).FirstOrDefault(delegate(ConstructorInfo ci)
{
ParameterInfo[] parameters2 = ci.GetParameters();
return parameters2.Length == 0 || parameters2.All((ParameterInfo pi) => pi.HasDefaultValue);
});
if (constructorInfo == null)
{
throw new InvalidOperationException("A default constructor was not found on " + type2.FullName + ".");
}
object[] parameters = (from pi in constructorInfo.GetParameters()
select pi.DefaultValue).ToArray();
return constructorInfo.Invoke(parameters);
}
}
if (toType2.IsArray && toType2.GetArrayRank() == 1)
{
Type elementType = toType2.GetElementType();
if (string.IsNullOrEmpty(value))
{
return Array.CreateInstance(elementType, 0);
}
string[] array = value.Split(new char[1] { ',' });
int num = array.Length;
Array array2 = Array.CreateInstance(elementType, array.Length);
for (int i = 0; i < num; i++)
{
object value2 = ConvertToType(array[i], elementType);
array2.SetValue(value2, i);
}
return array2;
}
return Convert.ChangeType(value, toType2);
}
internal static bool TryParseStaticMemberAccessor(string input, [NotNullWhen(true)] out string? accessorTypeName, [NotNullWhen(true)] out string? memberName)
{
if (StaticMemberAccessorRegex.IsMatch(input))
{
Match match = StaticMemberAccessorRegex.Match(input);
string value = match.Groups["shortTypeName"].Value;
string value2 = match.Groups["memberName"].Value;
string value3 = match.Groups["typeNameExtraQualifiers"].Value;
memberName = value2.Trim();
accessorTypeName = value.Trim() + value3.TrimEnd(Array.Empty<char>());
return true;
}
accessorTypeName = null;
memberName = null;
return false;
}
}
internal static class SurrogateConfigurationMethods
{
private static readonly Dictionary<Type, MethodInfo[]> SurrogateMethodCandidates = (from m in typeof(SurrogateConfigurationMethods).GetTypeInfo().DeclaredMethods
group m by m.GetParameters().First().ParameterType).ToDictionary((IGrouping<Type, MethodInfo> g) => g.Key, (IGrouping<Type, MethodInfo> g) => g.ToArray());
internal static readonly MethodInfo[] WriteTo = SurrogateMethodCandidates[typeof(LoggerSinkConfiguration)];
internal static readonly MethodInfo[] AuditTo = SurrogateMethodCandidates[typeof(LoggerAuditSinkConfiguration)];
internal static readonly MethodInfo[] Enrich = SurrogateMethodCandidates[typeof(LoggerEnrichmentConfiguration)];
internal static readonly MethodInfo[] Destructure = SurrogateMethodCandidates[typeof(LoggerDestructuringConfiguration)];
internal static readonly MethodInfo[] Filter = SurrogateMethodCandidates[typeof(LoggerFilterConfiguration)];
internal static LoggerConfiguration Sink(LoggerSinkConfiguration loggerSinkConfiguration, ILogEventSink sink, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose, LoggingLevelSwitch? levelSwitch = null)
{
return loggerSinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch);
}
internal static LoggerConfiguration Sink(LoggerAuditSinkConfiguration auditSinkConfiguration, ILogEventSink sink, LogEventLevel restrictedToMinimumLevel = LogEventLevel.Verbose, LoggingLevelSwitch? levelSwitch = null)
{
return auditSinkConfiguration.Sink(sink, restrictedToMinimumLevel, levelSwitch);
}
internal static LoggerConfiguration With(LoggerEnrichmentConfiguration loggerEnrichmentConfiguration, ILogEventEnricher enricher)
{
return loggerEnrichmentConfiguration.With(enricher);
}
internal static LoggerConfiguration FromLogContext(LoggerEnrichmentConfiguration loggerEnrichmentConfiguration)
{
return loggerEnrichmentConfiguration.FromLogContext();
}
internal static LoggerConfiguration With(LoggerDestructuringConfiguration loggerDestructuringConfiguration, IDestructuringPolicy policy)
{
return loggerDestructuringConfiguration.With(policy);
}
internal static LoggerConfiguration AsScalar(LoggerDestructuringConfiguration loggerDestructuringConfiguration, Type scalarType)
{
return loggerDestructuringConfiguration.AsScalar(scalarType);
}
internal static LoggerConfiguration ToMaximumCollectionCount(LoggerDestructuringConfiguration loggerDestructuringConfiguration, int maximumCollectionCount)
{
return loggerDestructuringConfiguration.ToMaximumCollectionCount(maximumCollectionCount);
}
internal static LoggerConfiguration ToMaximumDepth(LoggerDestructuringConfiguration loggerDestructuringConfiguration, int maximumDestructuringDepth)
{
return loggerDestructuringConfiguration.ToMaximumDepth(maximumDestructuringDepth);
}
internal static LoggerConfiguration ToMaximumStringLength(LoggerDestructuringConfiguration loggerDestructuringConfiguration, int maximumStringLength)
{
return loggerDestructuringConfiguration.ToMaximumStringLength(maximumStringLength);
}
internal static LoggerConfiguration With(LoggerFilterConfiguration loggerFilterConfiguration, ILogEventFilter filter)
{
return loggerFilterConfiguration.With(filter);
}
}
}
namespace Serilog.Rendering
{
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 MessageTemplateRenderer
{
private static readonly JsonValueFormatter JsonValueFormatter = new JsonValueFormatter("$type");
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Render(MessageTemplate messageTemplate, IReadOnlyDictionary<string, LogEventPropertyValue> properties, TextWriter output, string? format = null, IFormatProvider? formatProvider = null)
{
bool isLiteral = false;
bool isJson = false;
if (format != null)
{
for (int i = 0; i < format.Length; i++)
{
if (format[i] == 'l')
{
isLiteral = true;
}
else if (format[i] == 'j')
{
isJson = true;
}
}
}
for (int j = 0; j < messageTemplate.TokenArray.Length; j++)
{
MessageTemplateToken messageTemplateToken = messageTemplate.TokenArray[j];
if (messageTemplateToken is TextToken tt)
{
RenderTextToken(tt, output);
}
else
{
RenderPropertyToken((PropertyToken)messageTemplateToken, properties, output, formatProvider, isLiteral, isJson);
}
}
}
public static void RenderTextToken(TextToken tt, TextWriter output)
{
output.Write(tt.Text);
}
public static void RenderPropertyToken(PropertyToken pt, IReadOnlyDictionary<string, LogEventPropertyValue> properties, TextWriter output, IFormatProvider? formatProvider, bool isLiteral, bool isJson)
{
if (!properties.TryGetValue(pt.PropertyName, out LogEventPropertyValue value))
{
output.Write(pt.RawText);
return;
}
if (!pt.Alignment.HasValue)
{
RenderValue(value, isLiteral, isJson, output, pt.Format, formatProvider);
return;
}
using StringWriter stringWriter = ReusableStringWriter.GetOrCreate();
RenderValue(value, isLiteral, isJson, stringWriter, pt.Format, formatProvider);
StringBuilder stringBuilder = stringWriter.GetStringBuilder();
if (stringBuilder.Length >= pt.Alignment.Value.Width)
{
output.Write(stringBuilder.ToString());
return;
}
string value2 = stringBuilder.ToString();
Alignment? alignment = pt.Alignment.Value;
Padding.Apply(output, value2, in alignment);
}
private static void RenderValue(LogEventPropertyValue propertyValue, bool literal, bool json, TextWriter output, string? format, IFormatProvider? formatProvider)
{
if (literal && propertyValue is ScalarValue scalarValue && scalarValue.Value is string value)
{
output.Write(value);
}
else if (json && format == null)
{
JsonValueFormatter.Format(propertyValue, output);
}
else
{
propertyValue.Render(output, format, formatProvider);
}
}
}
internal static class Padding
{
private static readonly char[] PaddingChars = Enumerable.Repeat(' ', 80).ToArray();
public static void Apply(TextWriter output, string value, in Alignment? alignment)
{
if (!alignment.HasValue || value.Length >= alignment.Value.Width)
{
output.Write(value);
return;
}
int num = alignment.Value.Width - value.Length;
if (alignment.Value.Direction == AlignmentDirection.Left)
{
output.Write(value);
}
if (num <= PaddingChars.Length)
{
output.Write(PaddingChars, 0, num);
}
else
{
output.Write(new string(' ', num));
}
if (alignment.Value.Direction == AlignmentDirection.Right)
{
output.Write(value);
}
}
}
internal sealed class ReusableStringWriter : StringWriter
{
[ThreadStatic]
private static ReusableStringWriter? _pooledWriter;
internal const int StringBuilderCapacityThreshold = 32768;
public static StringWriter GetOrCreate(IFormatProvider? formatProvider = null)
{
IFormatProvider objB = formatProvider ?? CultureInfo.CurrentCulture;
ReusableStringWriter reusableStringWriter = _pooledWriter;
_pooledWriter = null;
if (reusableStringWriter == null || !object.Equals(reusableStringWriter.FormatProvider, objB))
{
reusableStringWriter = new ReusableStringWriter(formatProvider);
}
return reusableStringWriter;
}
private ReusableStringWriter(IFormatProvider? formatProvider)
: base(formatProvider ?? CultureInfo.CurrentCulture)
{
}
protected override void Dispose(bool disposing)
{
if (!disposing)
{
base.Dispose(disposing);
return;
}
StringBuilder stringBuilder = GetStringBuilder();
if (stringBuilder.Capacity > 32768)
{
base.Dispose(disposing);
return;
}
stringBuilder.Clear();
_pooledWriter = this;
}
}
}
namespace Serilog.Policies
{
internal class ByteArrayScalarConversionPolicy : IScalarConversionPolicy
{
private const int MaximumByteArrayLength = 1024;
public bool TryConvertToScalar(object value, [NotNullWhen(true)] out ScalarValue? result)
{
if (!(value is byte[] array))
{
result = null;
return false;
}
if (array.Length > 1024)
{
string value2 = string.Concat(string.Concat(from b in array.Take(16)
select b.ToString("X2")), "... (", array.Length.ToString(), " bytes)");
result = new ScalarValue(value2);
}
else
{
result = new ScalarValue(string.Concat(array.Select((byte b) => b.ToString("X2"))));
}
return true;
}
}
internal class DelegateDestructuringPolicy : IDestructuringPolicy
{
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result)
{
if (value is Delegate @delegate)
{
result = new ScalarValue(@delegate.ToString());
return true;
}
result = null;
return false;
}
}
internal class EnumScalarConversionPolicy : IScalarConversionPolicy
{
public bool TryConvertToScalar(object value, [NotNullWhen(true)] out ScalarValue? result)
{
if (value is Enum)
{
result = new ScalarValue(value);
return true;
}
result = null;
return false;
}
}
internal class PrimitiveScalarConversionPolicy : IScalarConversionPolicy
{
public bool TryConvertToScalar(object value, [NotNullWhen(true)] out ScalarValue? result)
{
if (value.GetType().IsPrimitive)
{
result = new ScalarValue(value);
return true;
}
result = null;
return false;
}
}
internal class ProjectedDestructuringPolicy : IDestructuringPolicy
{
private readonly Func<Type, bool> _canApply;
private readonly Func<object, object> _projection;
public ProjectedDestructuringPolicy(Func<Type, bool> canApply, Func<object, object> projection)
{
_canApply = Guard.AgainstNull(canApply, "canApply");
_projection = Guard.AgainstNull(projection, "projection");
}
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result)
{
Guard.AgainstNull(value, "value");
if (!_canApply(value.GetType()))
{
result = null;
return false;
}
object value2 = _projection(value);
result = propertyValueFactory.CreatePropertyValue(value2, destructureObjects: true);
return true;
}
}
internal class ReflectionTypesScalarDestructuringPolicy : IDestructuringPolicy
{
public bool TryDestructure(object value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventPropertyValue? result)
{
if ((value is Type || value is MemberInfo) ? true : false)
{
result = new ScalarValue(value);
return true;
}
result = null;
return false;
}
}
internal class SimpleScalarConversionPolicy : IScalarConversionPolicy
{
private readonly HashSet<Type> _scalarTypes;
public SimpleScalarConversionPolicy(IEnumerable<Type> scalarTypes)
{
HashSet<Type> hashSet = new HashSet<Type>();
foreach (Type scalarType in scalarTypes)
{
hashSet.Add(scalarType);
}
_scalarTypes = hashSet;
}
public bool TryConvertToScalar(object value, [NotNullWhen(true)] out ScalarValue? result)
{
if (_scalarTypes.Contains(value.GetType()))
{
result = new ScalarValue(value);
return true;
}
result = null;
return false;
}
}
}
namespace Serilog.Parsing
{
public readonly struct Alignment
{
public AlignmentDirection Direction { get; }
public int Width { get; }
public Alignment(AlignmentDirection direction, int width)
{
Direction = direction;
Width = width;
}
}
public enum AlignmentDirection
{
Left,
Right
}
public enum Destructuring
{
Default,
Stringify,
Destructure
}
public class MessageTemplateParser : IMessageTemplateParser
{
[CompilerGenerated]
private sealed class <Tokenize>d__3 : IEnumerable<MessageTemplateToken>, IEnumerable, IEnumerator<MessageTemplateToken>, IEnumerator, IDisposable
{
private int <>1__state;
private MessageTemplateToken <>2__current;
private int <>l__initialThreadId;
private string messageTemplate;
public string <>3__messageTemplate;
public MessageTemplateParser <>4__this;
private int <nextIndex>5__2;
MessageTemplateToken IEnumerator<MessageTemplateToken>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Tokenize>d__3(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
int num = <>1__state;
MessageTemplateParser messageTemplateParser = <>4__this;
int num2;
MessageTemplateToken messageTemplateToken;
int num3;
TextToken textToken;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
if (messageTemplate.Length == 0)
{
<>2__current = EmptyTextToken;
<>1__state = 1;
return true;
}
<nextIndex>5__2 = 0;
goto IL_005e;
case 1:
<>1__state = -1;
return false;
case 2:
<>1__state = -1;
goto IL_009d;
case 3:
{
<>1__state = -1;
goto IL_00f2;
}
IL_009d:
if (<nextIndex>5__2 == messageTemplate.Length)
{
return false;
}
num2 = <nextIndex>5__2;
messageTemplateToken = messageTemplateParser.ParsePropertyToken(<nextIndex>5__2, messageTemplate, out <nextIndex>5__2);
if (num2 < <nextIndex>5__2)
{
<>2__current = messageTemplateToken;
<>1__state = 3;
return true;
}
goto IL_00f2;
IL_005e:
num3 = <nextIndex>5__2;
textToken = ParseTextToken(<nextIndex>5__2, messageTemplate, out <nextIndex>5__2);
if (<nextIndex>5__2 > num3)
{
<>2__current = textToken;
<>1__state = 2;
return true;
}
goto IL_009d;
IL_00f2:
if (<nextIndex>5__2 == messageTemplate.Length)
{
return false;
}
goto IL_005e;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<MessageTemplateToken> IEnumerable<MessageTemplateToken>.GetEnumerator()
{
<Tokenize>d__3 <Tokenize>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<Tokenize>d__ = this;
}
else
{
<Tokenize>d__ = new <Tokenize>d__3(0)
{
<>4__this = <>4__this
};
}
<Tokenize>d__.messageTemplate = <>3__messageTemplate;
return <Tokenize>d__;
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<MessageTemplateToken>)this).GetEnumerator();
}
}
private static readonly TextToken EmptyTextToken = new TextToken("");
private static readonly char[] CurlyBraceChars = new char[2] { '{', '}' };
public MessageTemplate Parse(string messageTemplate)
{
Guard.AgainstNull(messageTemplate, "messageTemplate");
return new MessageTemplate(messageTemplate, Tokenize(messageTemplate));
}
[IteratorStateMachine(typeof(<Tokenize>d__3))]
private IEnumerable<MessageTemplateToken> Tokenize(string messageTemplate)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <Tokenize>d__3(-2)
{
<>4__this = this,
<>3__messageTemplate = messageTemplate
};
}
private MessageTemplateToken ParsePropertyToken(int startAt, string messageTemplate, out int next)
{
int num = startAt;
startAt++;
startAt = messageTemplate.IndexOf('}', startAt);
if (startAt == -1)
{
next = messageTemplate.Length;
string text = messageTemplate;
int num2 = num;
return new TextToken(text.Substring(num2, text.Length - num2));
}
next = startAt + 1;
string text2 = messageTemplate.Substring(num, next - num);
string text3 = text2.Substring(1, next - (num + 2));
if (text3.Length == 0)
{
return new TextToken(text2);
}
if (!TrySplitTagContent(text3, out string propertyNameAndDestructuring, out string format, out string alignment))
{
return new TextToken(text2);
}
string text4 = propertyNameAndDestructuring;
Destructuring destructuring = Destructuring.Default;
if (text4.Length != 0 && TryGetDestructuringHint(text4[0], out destructuring))
{
string text = text4;
text4 = text.Substring(1, text.Length - 1);
}
if (text4.Length == 0)
{
return new TextToken(text2);
}
if (char.IsDigit(text4[0]))
{
for (int i = 0; i < text4.Length; i++)
{
if (!char.IsDigit(text4[i]))
{
return new TextToken(text2);
}
}
}
else
{
bool beginIdent = true;
for (int j = 0; j < text4.Length; j++)
{
if (!TryContinuePropertyName(text4[j], ref beginIdent))
{
return new TextToken(text2);
}
}
if (beginIdent)
{
return new TextToken(text2);
}
}
if (format != null)
{
for (int k = 0; k < format.Length; k++)
{
if (!IsValidInFormat(format[k]))
{
return new TextToken(text2);
}
}
}
Alignment? alignment2 = null;
if (alignment != null)
{
if (alignment[0] == '+')
{
return new TextToken(text2);
}
if (!int.TryParse(alignment, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var result))
{
return new TextToken(text2);
}
AlignmentDirection direction = ((alignment[0] != '-') ? AlignmentDirection.Right : AlignmentDirection.Left);
alignment2 = new Alignment(direction, Math.Abs(result));
}
return new PropertyToken(text4, text2, format, in alignment2, destructuring);
}
private static bool TrySplitTagContent(string tagContent, [NotNullWhen(true)] out string? propertyNameAndDestructuring, out string? format, out string? alignment)
{
int num = tagContent.IndexOf(':');
int num2 = tagContent.IndexOf(',');
if (num == -1 && num2 == -1)
{
propertyNameAndDestructuring = tagContent;
format = null;
alignment = null;
return true;
}
if (num2 == -1 || (num != -1 && num2 > num))
{
propertyNameAndDestructuring = tagContent.Substring(0, num);
format = ((num == tagContent.Length - 1) ? null : tagContent.Substring(num + 1));
alignment = null;
return true;
}
propertyNameAndDestructuring = tagContent.Substring(0, num2);
if (num == -1)
{
if (num2 == tagContent.Length - 1)
{
alignment = (format = null);
return false;
}
format = null;
string text = tagContent;
int num3 = num2 + 1;
alignment = text.Substring(num3, text.Length - num3);
return true;
}
if (num2 == num - 1)
{
alignment = (format = null);
return false;
}
alignment = tagContent.Substring(num2 + 1, num - num2 - 1);
object obj;
if (num != tagContent.Length - 1)
{
string text = tagContent;
int num3 = num + 1;
obj = text.Substring(num3, text.Length - num3);
}
else
{
obj = null;
}
format = (string?)obj;
return true;
}
private static bool TryContinuePropertyName(char c, ref bool beginIdent)
{
if (beginIdent)
{
if (char.IsLetter(c) || c == '_')
{
beginIdent = false;
return true;
}
return false;
}
if (!char.IsLetterOrDigit(c))
{
switch (c)
{
case '_':
break;
case '.':
beginIdent = true;
return true;
default:
return false;
}
}
return true;
}
private static bool TryGetDestructuringHint(char c, out Destructuring destructuring)
{
switch (c)
{
case '@':
destructuring = Destructuring.Destructure;
return true;
case '$':
destructuring = Destructuring.Stringify;
return true;
default:
destructuring = Destructuring.Default;
return false;
}
}
private static bool IsValidInFormat(char c)
{
return c != '}';
}
private static TextToken ParseTextToken(int startAt, string messageTemplate, out int next)
{
int num = messageTemplate.IndexOfAny(CurlyBraceChars, startAt);
if (num == -1)
{
next = messageTemplate.Length;
return new TextToken(messageTemplate.Substring(startAt, messageTemplate.Length - startAt));
}
char c = messageTemplate[num];
num++;
StringBuilder stringBuilder;
if (c == '{')
{
if (num >= messageTemplate.Length