using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
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 Microsoft.CodeAnalysis;
using Serilog.Configuration;
using Serilog.Core;
using Serilog.Debugging;
using Serilog.Events;
using Serilog.Formatting;
using Serilog.Formatting.Display;
using Serilog.Sinks.File;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: CLSCompliant(true)]
[assembly: InternalsVisibleTo("Serilog.Sinks.File.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100fb8d13fd344a1c6fe0fe83ef33c1080bf30690765bc6eb0df26ebfdf8f21670c64265b30db09f73a0dea5b3db4c9d18dbf6d5a25af5ce9016f281014d79dc3b4201ac646c451830fc7e61a2dfd633d34c39f87b81894191652df5ac63cc40c77f3542f702bda692e6e8a9158353df189007a49da0f3cfd55eb250066b19485ec")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("Serilog Contributors")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Write Serilog events to text files in plain or JSON format.")]
[assembly: AssemblyFileVersion("7.0.0.0")]
[assembly: AssemblyInformationalVersion("7.0.0-main-23c732a+23c732a8658a0df2a5434fe69b0011800b14f0da")]
[assembly: AssemblyProduct("Serilog.Sinks.File")]
[assembly: AssemblyTitle("Serilog.Sinks.File")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/serilog/serilog-sinks-file")]
[assembly: AssemblyVersion("7.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 FileLoggerConfigurationExtensions
{
private const int DefaultRetainedFileCountLimit = 31;
private const long DefaultFileSizeLimitBytes = 1073741824L;
private const string DefaultOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}";
[Obsolete("New code should not be compiled against this obsolete overload")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static LoggerConfiguration File(this LoggerSinkConfiguration sinkConfiguration, string path, LogEventLevel restrictedToMinimumLevel, string outputTemplate, IFormatProvider formatProvider, long? fileSizeLimitBytes, LoggingLevelSwitch levelSwitch, bool buffered, bool shared, TimeSpan? flushToDiskInterval)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return sinkConfiguration.File(path, restrictedToMinimumLevel, outputTemplate, formatProvider, fileSizeLimitBytes, levelSwitch, buffered, shared, flushToDiskInterval, RollingInterval.Infinite, rollOnFileSizeLimit: false, null);
}
[Obsolete("New code should not be compiled against this obsolete overload")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static LoggerConfiguration File(this LoggerSinkConfiguration sinkConfiguration, ITextFormatter formatter, string path, LogEventLevel restrictedToMinimumLevel, long? fileSizeLimitBytes, LoggingLevelSwitch levelSwitch, bool buffered, bool shared, TimeSpan? flushToDiskInterval)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
return sinkConfiguration.File(formatter, path, restrictedToMinimumLevel, fileSizeLimitBytes, levelSwitch, buffered, shared, flushToDiskInterval, RollingInterval.Infinite, rollOnFileSizeLimit: false, null);
}
[Obsolete("New code should not be compiled against this obsolete overload")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static LoggerConfiguration File(this LoggerSinkConfiguration sinkConfiguration, string path, LogEventLevel restrictedToMinimumLevel, string outputTemplate, IFormatProvider formatProvider, long? fileSizeLimitBytes, LoggingLevelSwitch levelSwitch, bool buffered, bool shared, TimeSpan? flushToDiskInterval, RollingInterval rollingInterval, bool rollOnFileSizeLimit, int? retainedFileCountLimit, Encoding encoding)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return sinkConfiguration.File(path, restrictedToMinimumLevel, outputTemplate, formatProvider, fileSizeLimitBytes, levelSwitch, buffered, shared, flushToDiskInterval, rollingInterval, rollOnFileSizeLimit, retainedFileCountLimit, encoding, null, null);
}
[Obsolete("New code should not be compiled against this obsolete overload")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static LoggerConfiguration File(this LoggerSinkConfiguration sinkConfiguration, ITextFormatter formatter, string path, LogEventLevel restrictedToMinimumLevel, long? fileSizeLimitBytes, LoggingLevelSwitch levelSwitch, bool buffered, bool shared, TimeSpan? flushToDiskInterval, RollingInterval rollingInterval, bool rollOnFileSizeLimit, int? retainedFileCountLimit, Encoding encoding)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
return sinkConfiguration.File(formatter, path, restrictedToMinimumLevel, fileSizeLimitBytes, levelSwitch, buffered, shared, flushToDiskInterval, rollingInterval, rollOnFileSizeLimit, retainedFileCountLimit, encoding, null, null);
}
public static LoggerConfiguration File(this LoggerSinkConfiguration sinkConfiguration, string path, LogEventLevel restrictedToMinimumLevel = 0, string outputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}", IFormatProvider? formatProvider = null, long? fileSizeLimitBytes = 1073741824L, LoggingLevelSwitch? levelSwitch = null, bool buffered = false, bool shared = false, TimeSpan? flushToDiskInterval = null, RollingInterval rollingInterval = RollingInterval.Infinite, bool rollOnFileSizeLimit = false, int? retainedFileCountLimit = 31, Encoding? encoding = null, FileLifecycleHooks? hooks = null, TimeSpan? retainedFileTimeLimit = null)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
if (sinkConfiguration == null)
{
throw new ArgumentNullException("sinkConfiguration");
}
if (path == null)
{
throw new ArgumentNullException("path");
}
if (outputTemplate == null)
{
throw new ArgumentNullException("outputTemplate");
}
MessageTemplateTextFormatter formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
return sinkConfiguration.File((ITextFormatter)(object)formatter, path, restrictedToMinimumLevel, fileSizeLimitBytes, levelSwitch, buffered, shared, flushToDiskInterval, rollingInterval, rollOnFileSizeLimit, retainedFileCountLimit, encoding, hooks, retainedFileTimeLimit);
}
public static LoggerConfiguration File(this LoggerSinkConfiguration sinkConfiguration, ITextFormatter formatter, string path, LogEventLevel restrictedToMinimumLevel = 0, long? fileSizeLimitBytes = 1073741824L, LoggingLevelSwitch? levelSwitch = null, bool buffered = false, bool shared = false, TimeSpan? flushToDiskInterval = null, RollingInterval rollingInterval = RollingInterval.Infinite, bool rollOnFileSizeLimit = false, int? retainedFileCountLimit = 31, Encoding? encoding = null, FileLifecycleHooks? hooks = null, TimeSpan? retainedFileTimeLimit = null)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
if (sinkConfiguration == null)
{
throw new ArgumentNullException("sinkConfiguration");
}
if (formatter == null)
{
throw new ArgumentNullException("formatter");
}
if (path == null)
{
throw new ArgumentNullException("path");
}
return ((Func<ILogEventSink, LogEventLevel, LoggingLevelSwitch?, LoggerConfiguration>)sinkConfiguration.Sink).ConfigureFile(formatter, path, restrictedToMinimumLevel, fileSizeLimitBytes, levelSwitch, buffered, propagateExceptions: false, shared, flushToDiskInterval, encoding, rollingInterval, rollOnFileSizeLimit, retainedFileCountLimit, hooks, retainedFileTimeLimit);
}
[Obsolete("New code should not be compiled against this obsolete overload")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static LoggerConfiguration File(this LoggerAuditSinkConfiguration sinkConfiguration, string path, LogEventLevel restrictedToMinimumLevel, string outputTemplate, IFormatProvider formatProvider, LoggingLevelSwitch levelSwitch)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return sinkConfiguration.File(path, restrictedToMinimumLevel, outputTemplate, formatProvider, levelSwitch, null, null);
}
[Obsolete("New code should not be compiled against this obsolete overload")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static LoggerConfiguration File(this LoggerAuditSinkConfiguration sinkConfiguration, ITextFormatter formatter, string path, LogEventLevel restrictedToMinimumLevel, LoggingLevelSwitch levelSwitch)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
return sinkConfiguration.File(formatter, path, restrictedToMinimumLevel, levelSwitch, null, null);
}
public static LoggerConfiguration File(this LoggerAuditSinkConfiguration sinkConfiguration, string path, LogEventLevel restrictedToMinimumLevel = 0, string outputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}", IFormatProvider? formatProvider = null, LoggingLevelSwitch? levelSwitch = null, Encoding? encoding = null, FileLifecycleHooks? hooks = null)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Expected O, but got Unknown
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
if (sinkConfiguration == null)
{
throw new ArgumentNullException("sinkConfiguration");
}
if (path == null)
{
throw new ArgumentNullException("path");
}
if (outputTemplate == null)
{
throw new ArgumentNullException("outputTemplate");
}
MessageTemplateTextFormatter formatter = new MessageTemplateTextFormatter(outputTemplate, formatProvider);
return sinkConfiguration.File((ITextFormatter)(object)formatter, path, restrictedToMinimumLevel, levelSwitch, encoding, hooks);
}
public static LoggerConfiguration File(this LoggerAuditSinkConfiguration sinkConfiguration, ITextFormatter formatter, string path, LogEventLevel restrictedToMinimumLevel = 0, LoggingLevelSwitch? levelSwitch = null, Encoding? encoding = null, FileLifecycleHooks? hooks = null)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
if (sinkConfiguration == null)
{
throw new ArgumentNullException("sinkConfiguration");
}
if (formatter == null)
{
throw new ArgumentNullException("formatter");
}
if (path == null)
{
throw new ArgumentNullException("path");
}
return ((Func<ILogEventSink, LogEventLevel, LoggingLevelSwitch?, LoggerConfiguration>)sinkConfiguration.Sink).ConfigureFile(formatter, path, restrictedToMinimumLevel, (long?)null, levelSwitch, buffered: false, propagateExceptions: true, shared: false, (TimeSpan?)null, encoding, RollingInterval.Infinite, rollOnFileSizeLimit: false, (int?)null, hooks, (TimeSpan?)null);
}
private static LoggerConfiguration ConfigureFile(this Func<ILogEventSink, LogEventLevel, LoggingLevelSwitch?, LoggerConfiguration> addSink, ITextFormatter formatter, string path, LogEventLevel restrictedToMinimumLevel, long? fileSizeLimitBytes, LoggingLevelSwitch? levelSwitch, bool buffered, bool propagateExceptions, bool shared, TimeSpan? flushToDiskInterval, Encoding? encoding, RollingInterval rollingInterval, bool rollOnFileSizeLimit, int? retainedFileCountLimit, FileLifecycleHooks? hooks, TimeSpan? retainedFileTimeLimit)
{
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_017a: Unknown result type (might be due to invalid IL or missing references)
if (addSink == null)
{
throw new ArgumentNullException("addSink");
}
if (formatter == null)
{
throw new ArgumentNullException("formatter");
}
if (path == null)
{
throw new ArgumentNullException("path");
}
if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes.GetValueOrDefault() < 1)
{
throw new ArgumentException("Invalid value provided; file size limit must be at least 1 byte, or null.", "fileSizeLimitBytes");
}
if (retainedFileCountLimit.HasValue && retainedFileCountLimit.GetValueOrDefault() < 1)
{
throw new ArgumentException("At least one file must be retained.", "retainedFileCountLimit");
}
if (retainedFileTimeLimit.HasValue && retainedFileTimeLimit < TimeSpan.Zero)
{
throw new ArgumentException("Negative value provided; retained file time limit must be non-negative.", "retainedFileTimeLimit");
}
if (shared && buffered)
{
throw new ArgumentException("Buffered writes are not available when file sharing is enabled.", "buffered");
}
if (shared && hooks != null)
{
throw new ArgumentException("File lifecycle hooks are not currently supported for shared log files.", "hooks");
}
ILogEventSink val;
try
{
val = (ILogEventSink)((!rollOnFileSizeLimit && rollingInterval == RollingInterval.Infinite) ? ((!shared) ? ((object)new FileSink(path, formatter, fileSizeLimitBytes, encoding, buffered, hooks)) : ((object)new SharedFileSink(path, formatter, fileSizeLimitBytes, encoding))) : new RollingFileSink(path, formatter, fileSizeLimitBytes, retainedFileCountLimit, encoding, buffered, shared, rollingInterval, rollOnFileSizeLimit, hooks, retainedFileTimeLimit));
}
catch (Exception ex)
{
SelfLog.FailureListener.OnLoggingFailed((object)typeof(FileLoggerConfigurationExtensions), (LoggingFailureKind)2, "unable to open file sink for " + path, (IReadOnlyCollection<LogEvent>)null, ex);
if (propagateExceptions)
{
throw;
}
return addSink((ILogEventSink)(object)new FailedSink(), restrictedToMinimumLevel, levelSwitch);
}
if (flushToDiskInterval.HasValue)
{
val = (ILogEventSink)(object)new PeriodicFlushToDiskSink(val, flushToDiskInterval.Value);
}
return addSink(val, restrictedToMinimumLevel, levelSwitch);
}
}
public enum RollingInterval
{
Infinite,
Year,
Month,
Day,
Hour,
Minute
}
}
namespace Serilog.Sinks.File
{
internal static class Clock
{
private static Func<DateTime> _dateTimeNow = () => DateTime.Now;
[ThreadStatic]
private static DateTime _testDateTimeNow;
public static DateTime DateTimeNow => _dateTimeNow();
public static void SetTestDateTimeNow(DateTime now)
{
_testDateTimeNow = now;
_dateTimeNow = () => _testDateTimeNow;
}
}
internal sealed class FailedSink : ILogEventSink, ISetLoggingFailureListener
{
private ILoggingFailureListener _failureListener = SelfLog.FailureListener;
public void Emit(LogEvent logEvent)
{
_failureListener.OnLoggingFailed((object)this, (LoggingFailureKind)2, "the sink could not be initialized", (IReadOnlyCollection<LogEvent>)new <>z__ReadOnlySingleElementList<LogEvent>(logEvent), (Exception)null);
}
public void SetFailureListener(ILoggingFailureListener failureListener)
{
_failureListener = failureListener ?? throw new ArgumentNullException("failureListener");
}
}
internal sealed class FileLifeCycleHookChain : FileLifecycleHooks
{
private readonly FileLifecycleHooks _first;
private readonly FileLifecycleHooks _second;
public FileLifeCycleHookChain(FileLifecycleHooks first, FileLifecycleHooks second)
{
_first = first ?? throw new ArgumentNullException("first");
_second = second ?? throw new ArgumentNullException("second");
}
public override Stream OnFileOpened(string path, Stream underlyingStream, Encoding encoding)
{
Stream underlyingStream2 = _first.OnFileOpened(path, underlyingStream, encoding);
return _second.OnFileOpened(path, underlyingStream2, encoding);
}
public override void OnFileDeleting(string path)
{
_first.OnFileDeleting(path);
_second.OnFileDeleting(path);
}
}
public abstract class FileLifecycleHooks
{
public virtual Stream OnFileOpened(string path, Stream underlyingStream, Encoding encoding)
{
return OnFileOpened(underlyingStream, encoding);
}
public virtual Stream OnFileOpened(Stream underlyingStream, Encoding encoding)
{
return underlyingStream;
}
public virtual void OnFileDeleting(string path)
{
}
public FileLifecycleHooks Then(FileLifecycleHooks next)
{
return new FileLifeCycleHookChain(this, next);
}
}
public sealed class FileSink : IFileSink, ILogEventSink, IFlushableFileSink, IDisposable, ISetLoggingFailureListener
{
private readonly TextWriter _output;
private readonly FileStream _underlyingStream;
private readonly ITextFormatter _textFormatter;
private readonly long? _fileSizeLimitBytes;
private readonly bool _buffered;
private readonly object _syncRoot = new object();
private readonly WriteCountingStream? _countingStreamWrapper;
private ILoggingFailureListener _failureListener = SelfLog.FailureListener;
[Obsolete("This type and constructor will be removed from the public API in a future version; use `WriteTo.File()` instead.")]
public FileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, Encoding? encoding = null, bool buffered = false)
: this(path, textFormatter, fileSizeLimitBytes, encoding, buffered, null)
{
}
internal FileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, Encoding? encoding, bool buffered, FileLifecycleHooks? hooks)
{
if (path == null)
{
throw new ArgumentNullException("path");
}
if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes.GetValueOrDefault() < 1)
{
throw new ArgumentException("Invalid value provided; file size limit must be at least 1 byte, or null.");
}
_textFormatter = textFormatter ?? throw new ArgumentNullException("textFormatter");
_fileSizeLimitBytes = fileSizeLimitBytes;
_buffered = buffered;
string directoryName = Path.GetDirectoryName(path);
if (!string.IsNullOrWhiteSpace(directoryName) && !Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}
Stream stream = (_underlyingStream = System.IO.File.Open(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read));
stream.Seek(0L, SeekOrigin.End);
if (_fileSizeLimitBytes.HasValue)
{
stream = (_countingStreamWrapper = new WriteCountingStream(_underlyingStream));
}
if (encoding == null)
{
encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);
}
if (hooks != null)
{
try
{
stream = hooks.OnFileOpened(path, stream, encoding) ?? throw new InvalidOperationException("The file lifecycle hook `OnFileOpened(...)` returned `null`.");
}
catch
{
stream.Dispose();
throw;
}
}
_output = new StreamWriter(stream, encoding);
}
bool IFileSink.EmitOrOverflow(LogEvent logEvent)
{
if (logEvent == null)
{
throw new ArgumentNullException("logEvent");
}
lock (_syncRoot)
{
if (_fileSizeLimitBytes.HasValue && _countingStreamWrapper.CountedLength >= _fileSizeLimitBytes.Value)
{
return false;
}
_textFormatter.Format(logEvent, _output);
if (!_buffered)
{
_output.Flush();
}
return true;
}
}
public void Emit(LogEvent logEvent)
{
if (!((IFileSink)this).EmitOrOverflow(logEvent))
{
_failureListener.OnLoggingFailed((object)this, (LoggingFailureKind)1, "the log file size limit has been reached and no rolling behavior was specified", (IReadOnlyCollection<LogEvent>)new <>z__ReadOnlySingleElementList<LogEvent>(logEvent), (Exception)null);
}
}
public void Dispose()
{
lock (_syncRoot)
{
_output.Dispose();
}
}
public void FlushToDisk()
{
lock (_syncRoot)
{
_output.Flush();
_underlyingStream.Flush(flushToDisk: true);
}
}
void ISetLoggingFailureListener.SetFailureListener(ILoggingFailureListener failureListener)
{
_failureListener = failureListener ?? throw new ArgumentNullException("failureListener");
}
}
internal interface IFileSink : ILogEventSink, IFlushableFileSink
{
bool EmitOrOverflow(LogEvent logEvent);
}
public interface IFlushableFileSink
{
void FlushToDisk();
}
internal static class IOErrors
{
public static bool IsLockedFile(IOException ex)
{
return true;
}
}
internal sealed class NullSink : ILogEventSink
{
public void Emit(LogEvent logEvent)
{
}
}
internal sealed class PathRoller
{
[CompilerGenerated]
private sealed class <SelectMatches>d__15 : IEnumerable<RollingLogFile>, IEnumerable, IEnumerator<RollingLogFile>, IEnumerator, IDisposable
{
private int <>1__state;
private RollingLogFile <>2__current;
private int <>l__initialThreadId;
private IEnumerable<string> filenames;
public IEnumerable<string> <>3__filenames;
public PathRoller <>4__this;
private IEnumerator<string> <>7__wrap1;
RollingLogFile IEnumerator<RollingLogFile>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <SelectMatches>d__15(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<>7__wrap1 = null;
<>1__state = -2;
}
private bool MoveNext()
{
try
{
int num = <>1__state;
PathRoller pathRoller = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
<>7__wrap1 = filenames.GetEnumerator();
<>1__state = -3;
break;
case 1:
<>1__state = -3;
break;
}
while (<>7__wrap1.MoveNext())
{
string current = <>7__wrap1.Current;
Match match = pathRoller._filenameMatcher.Match(current);
if (match.Success)
{
int? sequenceNumber = null;
Group group = match.Groups["sequence"];
if (group.Captures.Count != 0)
{
string s = group.Captures[0].Value.Substring(1);
sequenceNumber = int.Parse(s, CultureInfo.InvariantCulture);
}
DateTime? dateTime = null;
Group group2 = match.Groups["period"];
if (group2.Captures.Count != 0 && DateTime.TryParseExact(group2.Captures[0].Value, pathRoller._periodFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out var result))
{
dateTime = result;
}
<>2__current = new RollingLogFile(current, dateTime, sequenceNumber);
<>1__state = 1;
return true;
}
}
<>m__Finally1();
<>7__wrap1 = null;
return false;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<>7__wrap1 != null)
{
<>7__wrap1.Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<RollingLogFile> IEnumerable<RollingLogFile>.GetEnumerator()
{
<SelectMatches>d__15 <SelectMatches>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<SelectMatches>d__ = this;
}
else
{
<SelectMatches>d__ = new <SelectMatches>d__15(0)
{
<>4__this = <>4__this
};
}
<SelectMatches>d__.filenames = <>3__filenames;
return <SelectMatches>d__;
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<RollingLogFile>)this).GetEnumerator();
}
}
private const string PeriodMatchGroup = "period";
private const string SequenceNumberMatchGroup = "sequence";
private readonly string _directory;
private readonly string _filenamePrefix;
private readonly string _filenameSuffix;
private readonly Regex _filenameMatcher;
private readonly RollingInterval _interval;
private readonly string _periodFormat;
public string LogFileDirectory => _directory;
public string DirectorySearchPattern { get; }
public PathRoller(string path, RollingInterval interval)
{
if (path == null)
{
throw new ArgumentNullException("path");
}
_interval = interval;
_periodFormat = interval.GetFormat();
string text = Path.GetDirectoryName(path);
if (string.IsNullOrEmpty(text))
{
text = Directory.GetCurrentDirectory();
}
_directory = Path.GetFullPath(text);
_filenamePrefix = Path.GetFileNameWithoutExtension(path);
_filenameSuffix = Path.GetExtension(path);
_filenameMatcher = new Regex("^" + Regex.Escape(_filenamePrefix) + "(?<period>\\d{" + _periodFormat.Length + "})(?<sequence>_[0-9]{3,}){0,1}" + Regex.Escape(_filenameSuffix) + "$", RegexOptions.Compiled);
DirectorySearchPattern = _filenamePrefix + "*" + _filenameSuffix;
}
public void GetLogFilePath(DateTime date, int? sequenceNumber, out string path)
{
string text = GetCurrentCheckpoint(date)?.ToString(_periodFormat, CultureInfo.InvariantCulture) ?? "";
if (sequenceNumber.HasValue)
{
text = text + "_" + sequenceNumber.Value.ToString("000", CultureInfo.InvariantCulture);
}
path = Path.Combine(_directory, _filenamePrefix + text + _filenameSuffix);
}
[IteratorStateMachine(typeof(<SelectMatches>d__15))]
public IEnumerable<RollingLogFile> SelectMatches(IEnumerable<string> filenames)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <SelectMatches>d__15(-2)
{
<>4__this = this,
<>3__filenames = filenames
};
}
public DateTime? GetCurrentCheckpoint(DateTime instant)
{
return _interval.GetCurrentCheckpoint(instant);
}
public DateTime? GetNextCheckpoint(DateTime instant)
{
return _interval.GetNextCheckpoint(instant);
}
}
[Obsolete("This type will be removed from the public API in a future version; use `WriteTo.File(flushToDiskInterval:)` instead.")]
public sealed class PeriodicFlushToDiskSink : ILogEventSink, IDisposable, ISetLoggingFailureListener
{
private readonly ILogEventSink _sink;
private readonly Timer _timer;
private int _flushRequired;
private ILoggingFailureListener _failureListener = SelfLog.FailureListener;
public PeriodicFlushToDiskSink(ILogEventSink sink, TimeSpan flushInterval)
{
PeriodicFlushToDiskSink periodicFlushToDiskSink = this;
_sink = sink ?? throw new ArgumentNullException("sink");
IFlushableFileSink flushable = sink as IFlushableFileSink;
if (flushable != null)
{
_timer = new Timer(delegate
{
periodicFlushToDiskSink.FlushToDisk(flushable);
}, null, flushInterval, flushInterval);
}
else
{
_timer = new Timer(delegate
{
}, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
SelfLog.FailureListener.OnLoggingFailed((object)this, (LoggingFailureKind)2, string.Format("configured to flush {0}, but {1} not implemented", sink, "IFlushableFileSink"), (IReadOnlyCollection<LogEvent>)null, (Exception)null);
}
}
public void Emit(LogEvent logEvent)
{
_sink.Emit(logEvent);
Interlocked.Exchange(ref _flushRequired, 1);
}
public void Dispose()
{
_timer.Dispose();
(_sink as IDisposable)?.Dispose();
}
private void FlushToDisk(IFlushableFileSink flushable)
{
try
{
if (Interlocked.CompareExchange(ref _flushRequired, 0, 1) == 1)
{
flushable.FlushToDisk();
}
}
catch (Exception ex)
{
_failureListener.OnLoggingFailed((object)this, (LoggingFailureKind)0, "could not flush the underlying file to disk", (IReadOnlyCollection<LogEvent>)null, ex);
}
}
void ISetLoggingFailureListener.SetFailureListener(ILoggingFailureListener failureListener)
{
_failureListener = failureListener ?? throw new ArgumentNullException("failureListener");
ILogEventSink sink = _sink;
ISetLoggingFailureListener val = (ISetLoggingFailureListener)(object)((sink is ISetLoggingFailureListener) ? sink : null);
if (val != null)
{
val.SetFailureListener(failureListener);
}
}
}
internal sealed class RollingFileSink : ILogEventSink, IFlushableFileSink, IDisposable, ISetLoggingFailureListener
{
private readonly PathRoller _roller;
private readonly ITextFormatter _textFormatter;
private readonly long? _fileSizeLimitBytes;
private readonly int? _retainedFileCountLimit;
private readonly TimeSpan? _retainedFileTimeLimit;
private readonly Encoding? _encoding;
private readonly bool _buffered;
private readonly bool _shared;
private readonly bool _rollOnFileSizeLimit;
private readonly FileLifecycleHooks? _hooks;
private ILoggingFailureListener _failureListener = SelfLog.FailureListener;
private readonly object _syncRoot = new object();
private bool _isDisposed;
private DateTime? _nextCheckpoint;
private IFileSink? _currentFile;
private int? _currentFileSequence;
public RollingFileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, int? retainedFileCountLimit, Encoding? encoding, bool buffered, bool shared, RollingInterval rollingInterval, bool rollOnFileSizeLimit, FileLifecycleHooks? hooks, TimeSpan? retainedFileTimeLimit)
{
if (path == null)
{
throw new ArgumentNullException("path");
}
if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes.GetValueOrDefault() < 1)
{
throw new ArgumentException("Invalid value provided; file size limit must be at least 1 byte, or null.");
}
if (retainedFileCountLimit.HasValue && retainedFileCountLimit.GetValueOrDefault() < 1)
{
throw new ArgumentException("Zero or negative value provided; retained file count limit must be at least 1.");
}
if (retainedFileTimeLimit.HasValue && retainedFileTimeLimit < TimeSpan.Zero)
{
throw new ArgumentException("Negative value provided; retained file time limit must be non-negative.", "retainedFileTimeLimit");
}
_roller = new PathRoller(path, rollingInterval);
_textFormatter = textFormatter;
_fileSizeLimitBytes = fileSizeLimitBytes;
_retainedFileCountLimit = retainedFileCountLimit;
_retainedFileTimeLimit = retainedFileTimeLimit;
_encoding = encoding;
_buffered = buffered;
_shared = shared;
_rollOnFileSizeLimit = rollOnFileSizeLimit;
_hooks = hooks;
}
public void Emit(LogEvent logEvent)
{
if (logEvent == null)
{
throw new ArgumentNullException("logEvent");
}
bool flag;
lock (_syncRoot)
{
if (_isDisposed)
{
throw new ObjectDisposedException("The log file has been disposed.");
}
DateTime dateTimeNow = Clock.DateTimeNow;
AlignCurrentFileTo(dateTimeNow);
while (true)
{
IFileSink? currentFile = _currentFile;
if (currentFile == null || currentFile.EmitOrOverflow(logEvent) || !_rollOnFileSizeLimit)
{
break;
}
AlignCurrentFileTo(dateTimeNow, nextSequence: true);
}
flag = _currentFile == null;
}
if (flag)
{
_failureListener.OnLoggingFailed((object)this, (LoggingFailureKind)1, "the target file could not be opened or created", (IReadOnlyCollection<LogEvent>)new <>z__ReadOnlySingleElementList<LogEvent>(logEvent), (Exception)null);
}
}
private void AlignCurrentFileTo(DateTime now, bool nextSequence = false)
{
if (_currentFile == null && !_nextCheckpoint.HasValue)
{
OpenFile(now);
}
else if (nextSequence || (_nextCheckpoint.HasValue && now >= _nextCheckpoint.Value))
{
int? minSequence = null;
if (nextSequence)
{
minSequence = (_currentFileSequence.HasValue ? new int?(_currentFileSequence.Value + 1) : new int?(1));
}
CloseFile();
OpenFile(now, minSequence);
}
}
private void OpenFile(DateTime now, int? minSequence = null)
{
DateTime? currentCheckpoint = _roller.GetCurrentCheckpoint(now);
_nextCheckpoint = _roller.GetNextCheckpoint(now);
try
{
IEnumerable<string> filenames = Enumerable.Empty<string>();
try
{
if (Directory.Exists(_roller.LogFileDirectory))
{
filenames = from f in Directory.GetFiles(_roller.LogFileDirectory, _roller.DirectorySearchPattern)
select Path.GetFileName(f);
}
}
catch (DirectoryNotFoundException)
{
}
int? num = (from m in _roller.SelectMatches(filenames).Where(delegate(RollingLogFile m)
{
DateTime? dateTime2 = m.DateTime;
DateTime? dateTime3 = currentCheckpoint;
if (dateTime2.HasValue != dateTime3.HasValue)
{
return false;
}
return !dateTime2.HasValue || dateTime2.GetValueOrDefault() == dateTime3.GetValueOrDefault();
})
orderby m.SequenceNumber descending
select m).FirstOrDefault()?.SequenceNumber;
if (minSequence.HasValue && (!num.HasValue || num.Value < minSequence.Value))
{
num = minSequence;
}
for (int i = 0; i < 3; i++)
{
_roller.GetLogFilePath(now, num, out string path);
try
{
IFileSink currentFile;
if (!_shared)
{
IFileSink fileSink = new FileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding, _buffered, _hooks);
currentFile = fileSink;
}
else
{
IFileSink fileSink = new SharedFileSink(path, _textFormatter, _fileSizeLimitBytes, _encoding);
currentFile = fileSink;
}
_currentFile = currentFile;
_currentFileSequence = num;
IFileSink? currentFile2 = _currentFile;
ISetLoggingFailureListener val = (ISetLoggingFailureListener)((currentFile2 is ISetLoggingFailureListener) ? currentFile2 : null);
if (val != null)
{
val.SetFailureListener(_failureListener);
}
}
catch (IOException ex2)
{
if (IOErrors.IsLockedFile(ex2))
{
_failureListener.OnLoggingFailed((object)this, (LoggingFailureKind)0, $"file target {path} was locked, attempting to open next in sequence (attempt {i + 1})", (IReadOnlyCollection<LogEvent>)null, (Exception)null);
num = num.GetValueOrDefault() + 1;
continue;
}
throw;
}
ApplyRetentionPolicy(path, now);
break;
}
}
finally
{
DateTime dateTime;
if (_currentFile == null)
{
dateTime = now.AddMinutes(30.0);
if (!_nextCheckpoint.HasValue)
{
goto IL_0243;
}
DateTime value = dateTime;
DateTime? nextCheckpoint = _nextCheckpoint;
if (value < nextCheckpoint)
{
goto IL_0243;
}
}
goto end_IL_01f4;
IL_0243:
_nextCheckpoint = dateTime;
end_IL_01f4:;
}
}
private void ApplyRetentionPolicy(string currentFilePath, DateTime now)
{
if (!_retainedFileCountLimit.HasValue && !_retainedFileTimeLimit.HasValue)
{
return;
}
string currentFileName = Path.GetFileName(currentFilePath);
IEnumerable<string> filenames = (from f in Directory.GetFiles(_roller.LogFileDirectory, _roller.DirectorySearchPattern)
select Path.GetFileName(f)).Union<string>(new <>z__ReadOnlySingleElementList<string>(currentFileName));
foreach (string item in (from x in (from m in _roller.SelectMatches(filenames)
orderby m.DateTime descending, m.SequenceNumber descending
select m into n
where StringComparer.OrdinalIgnoreCase.Compare(currentFileName, n.Filename) != 0
select n).SkipWhile((RollingLogFile f, int i) => ShouldRetainFile(f, i, now))
select x.Filename).ToList())
{
string text = Path.Combine(_roller.LogFileDirectory, item);
try
{
_hooks?.OnFileDeleting(text);
System.IO.File.Delete(text);
}
catch (Exception ex)
{
_failureListener.OnLoggingFailed((object)this, (LoggingFailureKind)0, "error while processing obsolete log file " + text, (IReadOnlyCollection<LogEvent>)null, ex);
}
}
}
private bool ShouldRetainFile(RollingLogFile file, int index, DateTime now)
{
if (_retainedFileCountLimit.HasValue && index >= _retainedFileCountLimit.Value - 1)
{
return false;
}
if (_retainedFileTimeLimit.HasValue && file.DateTime.HasValue && file.DateTime.Value < now.Subtract(_retainedFileTimeLimit.Value))
{
return false;
}
return true;
}
public void Dispose()
{
lock (_syncRoot)
{
if (_currentFile != null)
{
CloseFile();
_isDisposed = true;
}
}
}
private void CloseFile()
{
if (_currentFile != null)
{
(_currentFile as IDisposable)?.Dispose();
_currentFile = null;
}
_nextCheckpoint = null;
}
public void FlushToDisk()
{
lock (_syncRoot)
{
_currentFile?.FlushToDisk();
}
}
public void SetFailureListener(ILoggingFailureListener failureListener)
{
_failureListener = failureListener ?? throw new ArgumentNullException("failureListener");
}
}
internal static class RollingIntervalExtensions
{
public static string GetFormat(this RollingInterval interval)
{
return interval switch
{
RollingInterval.Infinite => "",
RollingInterval.Year => "yyyy",
RollingInterval.Month => "yyyyMM",
RollingInterval.Day => "yyyyMMdd",
RollingInterval.Hour => "yyyyMMddHH",
RollingInterval.Minute => "yyyyMMddHHmm",
_ => throw new ArgumentException("Invalid rolling interval."),
};
}
public static DateTime? GetCurrentCheckpoint(this RollingInterval interval, DateTime instant)
{
return interval switch
{
RollingInterval.Infinite => null,
RollingInterval.Year => new DateTime(instant.Year, 1, 1, 0, 0, 0, instant.Kind),
RollingInterval.Month => new DateTime(instant.Year, instant.Month, 1, 0, 0, 0, instant.Kind),
RollingInterval.Day => new DateTime(instant.Year, instant.Month, instant.Day, 0, 0, 0, instant.Kind),
RollingInterval.Hour => new DateTime(instant.Year, instant.Month, instant.Day, instant.Hour, 0, 0, instant.Kind),
RollingInterval.Minute => new DateTime(instant.Year, instant.Month, instant.Day, instant.Hour, instant.Minute, 0, instant.Kind),
_ => throw new ArgumentException("Invalid rolling interval."),
};
}
public static DateTime? GetNextCheckpoint(this RollingInterval interval, DateTime instant)
{
DateTime? currentCheckpoint = interval.GetCurrentCheckpoint(instant);
if (!currentCheckpoint.HasValue)
{
return null;
}
return interval switch
{
RollingInterval.Year => currentCheckpoint.Value.AddYears(1),
RollingInterval.Month => currentCheckpoint.Value.AddMonths(1),
RollingInterval.Day => currentCheckpoint.Value.AddDays(1.0),
RollingInterval.Hour => currentCheckpoint.Value.AddHours(1.0),
RollingInterval.Minute => currentCheckpoint.Value.AddMinutes(1.0),
_ => throw new ArgumentException("Invalid rolling interval."),
};
}
}
internal class RollingLogFile
{
public string Filename { get; }
public DateTime? DateTime { get; }
public int? SequenceNumber { get; }
public RollingLogFile(string filename, DateTime? dateTime, int? sequenceNumber)
{
Filename = filename;
DateTime = dateTime;
SequenceNumber = sequenceNumber;
base..ctor();
}
}
[Obsolete("This type will be removed from the public API in a future version; use `WriteTo.File(shared: true)` instead.")]
public sealed class SharedFileSink : IFileSink, ILogEventSink, IFlushableFileSink, IDisposable, ISetLoggingFailureListener
{
private readonly TextWriter _output;
private readonly FileStream _underlyingStream;
private readonly ITextFormatter _textFormatter;
private readonly long? _fileSizeLimitBytes;
private readonly object _syncRoot = new object();
private ILoggingFailureListener _failureListener = SelfLog.FailureListener;
private const string MutexNameSuffix = ".serilog";
private const int MutexWaitTimeout = 10000;
private readonly Mutex _mutex;
public SharedFileSink(string path, ITextFormatter textFormatter, long? fileSizeLimitBytes, Encoding? encoding = null)
{
if (path == null)
{
throw new ArgumentNullException("path");
}
if (fileSizeLimitBytes.HasValue && fileSizeLimitBytes.GetValueOrDefault() < 1)
{
throw new ArgumentException("Invalid value provided; file size limit must be at least 1 byte, or null.");
}
_textFormatter = textFormatter ?? throw new ArgumentNullException("textFormatter");
_fileSizeLimitBytes = fileSizeLimitBytes;
string directoryName = Path.GetDirectoryName(path);
if (!string.IsNullOrWhiteSpace(directoryName) && !Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}
string name = Path.GetFullPath(path).Replace(Path.DirectorySeparatorChar, ':') + ".serilog";
_mutex = new Mutex(initiallyOwned: false, name);
_underlyingStream = System.IO.File.Open(path, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
_output = new StreamWriter(_underlyingStream, encoding ?? new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
}
bool IFileSink.EmitOrOverflow(LogEvent logEvent)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
if (logEvent == null)
{
throw new ArgumentNullException("logEvent");
}
lock (_syncRoot)
{
if (!TryAcquireMutex())
{
throw new LoggingFailedException($"The shared file mutex could not be acquired within {10000} ms.");
}
try
{
_underlyingStream.Seek(0L, SeekOrigin.End);
if (_fileSizeLimitBytes.HasValue && _underlyingStream.Length >= _fileSizeLimitBytes.Value)
{
return false;
}
_textFormatter.Format(logEvent, _output);
_output.Flush();
_underlyingStream.Flush();
return true;
}
finally
{
ReleaseMutex();
}
}
}
public void Emit(LogEvent logEvent)
{
if (!((IFileSink)this).EmitOrOverflow(logEvent))
{
_failureListener.OnLoggingFailed((object)this, (LoggingFailureKind)1, "the log file size limit has been reached and no rolling behavior was specified", (IReadOnlyCollection<LogEvent>)new <>z__ReadOnlySingleElementList<LogEvent>(logEvent), (Exception)null);
}
}
public void Dispose()
{
lock (_syncRoot)
{
_output.Dispose();
_mutex.Dispose();
}
}
public void FlushToDisk()
{
lock (_syncRoot)
{
if (!TryAcquireMutex())
{
return;
}
try
{
_underlyingStream.Flush(flushToDisk: true);
}
finally
{
ReleaseMutex();
}
}
}
private bool TryAcquireMutex()
{
try
{
if (!_mutex.WaitOne(10000))
{
return false;
}
}
catch (AbandonedMutexException)
{
SelfLog.WriteLine("inherited the shared file mutex after abandonment by another process", (object)null, (object)null, (object)null);
}
return true;
}
private void ReleaseMutex()
{
_mutex.ReleaseMutex();
}
void ISetLoggingFailureListener.SetFailureListener(ILoggingFailureListener failureListener)
{
_failureListener = failureListener ?? throw new ArgumentNullException("failureListener");
}
}
internal sealed class WriteCountingStream : Stream
{
private readonly Stream _stream;
public long CountedLength { get; private set; }
public override bool CanRead => false;
public override bool CanSeek => _stream.CanSeek;
public override bool CanWrite => true;
public override long Length => _stream.Length;
public override long Position
{
get
{
return _stream.Position;
}
set
{
throw new NotSupportedException();
}
}
public WriteCountingStream(Stream stream)
{
_stream = stream ?? throw new ArgumentNullException("stream");
CountedLength = stream.Length;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
_stream.Dispose();
}
base.Dispose(disposing);
}
public override void Write(byte[] buffer, int offset, int count)
{
_stream.Write(buffer, offset, count);
CountedLength += count;
}
public override void Flush()
{
_stream.Flush();
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new InvalidOperationException("Seek operations are not available through `WriteCountingStream`.");
}
public override void SetLength(long value)
{
_stream.SetLength(value);
if (value < CountedLength)
{
CountedLength = _stream.Length;
}
}
public override int Read(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
}
}
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;
}
}
}
[CompilerGenerated]
internal sealed class <>z__ReadOnlySingleElementList<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
private sealed class Enumerator : IDisposable, IEnumerator, IEnumerator<T>
{
object IEnumerator.Current => _item;
T IEnumerator<T>.Current => _item;
public Enumerator(T item)
{
_item = item;
}
bool IEnumerator.MoveNext()
{
if (!_moveNextCalled)
{
return _moveNextCalled = true;
}
return false;
}
void IEnumerator.Reset()
{
_moveNextCalled = false;
}
void IDisposable.Dispose()
{
}
}
int ICollection.Count => 1;
bool ICollection.IsSynchronized => false;
object ICollection.SyncRoot => this;
object IList.this[int index]
{
get
{
if (index != 0)
{
throw new IndexOutOfRangeException();
}
return _item;
}
set
{
throw new NotSupportedException();
}
}
bool IList.IsFixedSize => true;
bool IList.IsReadOnly => true;
int IReadOnlyCollection<T>.Count => 1;
T IReadOnlyList<T>.this[int index]
{
get
{
if (index != 0)
{
throw new IndexOutOfRangeException();
}
return _item;
}
}
int ICollection<T>.Count => 1;
bool ICollection<T>.IsReadOnly => true;
T IList<T>.this[int index]
{
get
{
if (index != 0)
{
throw new IndexOutOfRangeException();
}
return _item;
}
set
{
throw new NotSupportedException();
}
}
public <>z__ReadOnlySingleElementList(T item)
{
_item = item;
}
IEnumerator IEnumerable.GetEnumerator()
{
return new Enumerator(_item);
}
void ICollection.CopyTo(Array array, int index)
{
array.SetValue(_item, index);
}
int IList.Add(object value)
{
throw new NotSupportedException();
}
void IList.Clear()
{
throw new NotSupportedException();
}
bool IList.Contains(object value)
{
return EqualityComparer<T>.Default.Equals(_item, (T)value);
}
int IList.IndexOf(object value)
{
if (!EqualityComparer<T>.Default.Equals(_item, (T)value))
{
return -1;
}
return 0;
}
void IList.Insert(int index, object value)
{
throw new NotSupportedException();
}
void IList.Remove(object value)
{
throw new NotSupportedException();
}
void IList.RemoveAt(int index)
{
throw new NotSupportedException();
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return new Enumerator(_item);
}
void ICollection<T>.Add(T item)
{
throw new NotSupportedException();
}
void ICollection<T>.Clear()
{
throw new NotSupportedException();
}
bool ICollection<T>.Contains(T item)
{
return EqualityComparer<T>.Default.Equals(_item, item);
}
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
{
array[arrayIndex] = _item;
}
bool ICollection<T>.Remove(T item)
{
throw new NotSupportedException();
}
int IList<T>.IndexOf(T item)
{
if (!EqualityComparer<T>.Default.Equals(_item, item))
{
return -1;
}
return 0;
}
void IList<T>.Insert(int index, T item)
{
throw new NotSupportedException();
}
void IList<T>.RemoveAt(int index)
{
throw new NotSupportedException();
}
}