using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using Microsoft.CodeAnalysis; using Serilog.Configuration; using Serilog.Core; using Serilog.Events; using Serilog.Sinks.Map; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: InternalsVisibleTo("Serilog.Sinks.Map.Tests, 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("A Serilog sink wrapper that dispatches events based on a property value.")] [assembly: AssemblyFileVersion("2.0.0.0")] [assembly: AssemblyInformationalVersion("2.0.0+5cff06e49235500f641296a4a8e8a56be7788dfe")] [assembly: AssemblyProduct("Serilog.Sinks.Map")] [assembly: AssemblyTitle("Serilog.Sinks.Map")] [assembly: AssemblyVersion("2.0.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] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Serilog { public static class MapLoggerConfigurationExtensions { public static LoggerConfiguration Map(this LoggerSinkConfiguration loggerSinkConfiguration, string keyPropertyName, string defaultKey, Action configure, int? sinkMapCountLimit = null, LogEventLevel restrictedToMinimumLevel = 0, LoggingLevelSwitch? levelSwitch = null) { //IL_0024: Unknown result type (might be due to invalid IL or missing references) string keyPropertyName2 = keyPropertyName; string defaultKey2 = defaultKey; return loggerSinkConfiguration.Map((Func)delegate(LogEvent le) { if (le.Properties.TryGetValue(keyPropertyName2, out var value)) { ScalarValue val = (ScalarValue)(object)((value is ScalarValue) ? value : null); if (val != null) { return val.Value?.ToString() ?? defaultKey2; } } return defaultKey2; }, configure, sinkMapCountLimit, restrictedToMinimumLevel, levelSwitch); } public static LoggerConfiguration Map(this LoggerSinkConfiguration loggerSinkConfiguration, string keyPropertyName, TKey defaultKey, Action configure, int? sinkMapCountLimit = null, LogEventLevel restrictedToMinimumLevel = 0, LoggingLevelSwitch? levelSwitch = null) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) string keyPropertyName2 = keyPropertyName; TKey defaultKey2 = defaultKey; if (loggerSinkConfiguration == null) { throw new ArgumentNullException("loggerSinkConfiguration"); } if (keyPropertyName2 == null) { throw new ArgumentNullException("keyPropertyName"); } if (configure == null) { throw new ArgumentNullException("configure"); } return loggerSinkConfiguration.Map(delegate(LogEvent le) { if (le.Properties.TryGetValue(keyPropertyName2, out var value)) { ScalarValue val = (ScalarValue)(object)((value is ScalarValue) ? value : null); if (val != null) { object value2 = val.Value; if (value2 is TKey) { return (TKey)value2; } } } return defaultKey2; }, configure, sinkMapCountLimit, restrictedToMinimumLevel, levelSwitch); } public static LoggerConfiguration Map(this LoggerSinkConfiguration loggerSinkConfiguration, Func keySelector, Action configure, int? sinkMapCountLimit = null, LogEventLevel restrictedToMinimumLevel = 0, LoggingLevelSwitch? levelSwitch = null) { //IL_006e: Unknown result type (might be due to invalid IL or missing references) Func keySelector2 = keySelector; if (loggerSinkConfiguration == null) { throw new ArgumentNullException("loggerSinkConfiguration"); } if (keySelector2 == null) { throw new ArgumentNullException("keySelector"); } if (configure == null) { throw new ArgumentNullException("configure"); } if (sinkMapCountLimit.HasValue && sinkMapCountLimit.GetValueOrDefault() < 0) { throw new ArgumentOutOfRangeException("sinkMapCountLimit"); } return loggerSinkConfiguration.Sink((ILogEventSink)(object)new MappedSink((LogEvent logEvent, [MaybeNull] out TKey key) => { key = keySelector2(logEvent); return true; }, configure, sinkMapCountLimit), restrictedToMinimumLevel, levelSwitch); } public static LoggerConfiguration Map(this LoggerSinkConfiguration loggerSinkConfiguration, string keyPropertyName, Action configure, int? sinkMapCountLimit = null, LogEventLevel restrictedToMinimumLevel = 0, LoggingLevelSwitch? levelSwitch = null) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) string keyPropertyName2 = keyPropertyName; return loggerSinkConfiguration.Map(delegate(LogEvent le, out string? key) { if (le.Properties.TryGetValue(keyPropertyName2, out var value)) { ScalarValue val = (ScalarValue)(object)((value is ScalarValue) ? value : null); if (val != null) { key = val.Value?.ToString(); return true; } } key = null; return false; }, configure, sinkMapCountLimit, restrictedToMinimumLevel, levelSwitch); } public static LoggerConfiguration Map(this LoggerSinkConfiguration loggerSinkConfiguration, string keyPropertyName, Action configure, int? sinkMapCountLimit = null, LogEventLevel restrictedToMinimumLevel = 0, LoggingLevelSwitch? levelSwitch = null) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) string keyPropertyName2 = keyPropertyName; if (loggerSinkConfiguration == null) { throw new ArgumentNullException("loggerSinkConfiguration"); } if (keyPropertyName2 == null) { throw new ArgumentNullException("keyPropertyName"); } if (configure == null) { throw new ArgumentNullException("configure"); } return loggerSinkConfiguration.Map(delegate(LogEvent le, out TKey? key) { if (le.Properties.TryGetValue(keyPropertyName2, out var value)) { ScalarValue val = (ScalarValue)(object)((value is ScalarValue) ? value : null); if (val != null && val.Value is TKey val2) { key = val2; return true; } } key = default(TKey); return false; }, configure, sinkMapCountLimit, restrictedToMinimumLevel, levelSwitch); } public static LoggerConfiguration Map(this LoggerSinkConfiguration loggerSinkConfiguration, KeySelector keySelector, Action configure, int? sinkMapCountLimit = null, LogEventLevel restrictedToMinimumLevel = 0, LoggingLevelSwitch? levelSwitch = null) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) if (loggerSinkConfiguration == null) { throw new ArgumentNullException("loggerSinkConfiguration"); } if (keySelector == null) { throw new ArgumentNullException("keySelector"); } if (configure == null) { throw new ArgumentNullException("configure"); } if (sinkMapCountLimit.HasValue && sinkMapCountLimit.GetValueOrDefault() < 0) { throw new ArgumentOutOfRangeException("sinkMapCountLimit"); } return loggerSinkConfiguration.Sink((ILogEventSink)(object)new MappedSink(keySelector, configure, sinkMapCountLimit), restrictedToMinimumLevel, levelSwitch); } } } namespace Serilog.Sinks.Map { public delegate bool KeySelector(LogEvent logEvent, [MaybeNull] out TKey key); internal class MappedSink : ILogEventSink, IDisposable { private readonly KeySelector _keySelector; private readonly Action _configure; private readonly int? _sinkMapCountLimit; private readonly object _sync = new object(); private readonly Dictionary, ILogEventSink> _sinkMap = new Dictionary, ILogEventSink>(); private bool _disposed; public MappedSink(KeySelector keySelector, Action configure, int? sinkMapCountLimit) { _keySelector = keySelector; _configure = configure; _sinkMapCountLimit = sinkMapCountLimit; } public void Emit(LogEvent logEvent) { if (!_keySelector(logEvent, out var key2)) { return; } KeyValuePair key = new KeyValuePair(key2, value: false); lock (_sync) { if (_disposed) { throw new ObjectDisposedException("MappedSink", "The mapped sink has been disposed."); } if (_sinkMap.TryGetValue(key, out ILogEventSink value)) { value.Emit(logEvent); return; } ILogEventSink val = LoggerSinkConfiguration.CreateSink((Action)delegate(LoggerSinkConfiguration wt) { _configure(key.Key, wt); }); if (_sinkMapCountLimit == 0) { using (val as IDisposable) { val.Emit(logEvent); return; } } if (!_sinkMapCountLimit.HasValue || _sinkMapCountLimit > _sinkMap.Count) { _sinkMap[key] = val; val.Emit(logEvent); return; } _sinkMap[key] = val; try { val.Emit(logEvent); } finally { while (_sinkMap.Count > _sinkMapCountLimit.Value) { foreach (KeyValuePair key3 in _sinkMap.Keys) { if (!key.Equals(key3)) { ILogEventSink obj = _sinkMap[key3]; _sinkMap.Remove(key3); (obj as IDisposable)?.Dispose(); break; } } } } } } public void Dispose() { lock (_sync) { if (!_disposed) { _disposed = true; ILogEventSink[] array = _sinkMap.Values.ToArray(); _sinkMap.Clear(); ILogEventSink[] array2 = array; for (int i = 0; i < array2.Length; i++) { (array2[i] as IDisposable)?.Dispose(); } } } } } } namespace System.Diagnostics.CodeAnalysis { [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)] [ExcludeFromCodeCoverage] [DebuggerNonUserCode] internal sealed class AllowNullAttribute : Attribute { } [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, Inherited = false)] [ExcludeFromCodeCoverage] [DebuggerNonUserCode] internal sealed class DisallowNullAttribute : Attribute { } [AttributeUsage(AttributeTargets.Method, Inherited = false)] [ExcludeFromCodeCoverage] [DebuggerNonUserCode] internal sealed class DoesNotReturnAttribute : Attribute { } [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] [ExcludeFromCodeCoverage] [DebuggerNonUserCode] internal sealed class DoesNotReturnIfAttribute : Attribute { public bool ParameterValue { get; } public DoesNotReturnIfAttribute(bool parameterValue) { ParameterValue = parameterValue; } } [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, Inherited = false)] [ExcludeFromCodeCoverage] [DebuggerNonUserCode] internal sealed class MaybeNullAttribute : Attribute { } [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] [ExcludeFromCodeCoverage] [DebuggerNonUserCode] 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] [DebuggerNonUserCode] 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] [DebuggerNonUserCode] 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] [DebuggerNonUserCode] internal sealed class NotNullAttribute : Attribute { } [AttributeUsage(AttributeTargets.Property | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = true, Inherited = false)] [ExcludeFromCodeCoverage] [DebuggerNonUserCode] internal sealed class NotNullIfNotNullAttribute : Attribute { public string ParameterName { get; } public NotNullIfNotNullAttribute(string parameterName) { ParameterName = parameterName; } } [AttributeUsage(AttributeTargets.Parameter, Inherited = false)] [ExcludeFromCodeCoverage] [DebuggerNonUserCode] internal sealed class NotNullWhenAttribute : Attribute { public bool ReturnValue { get; } public NotNullWhenAttribute(bool returnValue) { ReturnValue = returnValue; } } }