protected override void AddAppenderSpecificProperties() { base.AddAppenderSpecificProperties(); RollingStyle rollingStyle = new RollingStyle(); rollingStyle.PropertyChanged += RollingStyleOnPropertyChanged; AddProperty(rollingStyle); mDateTimeStrategyIndex = Properties.Count; AddRemoveBasedOnMode(rollingStyle.SelectedMode, mDateModes, mDateTimeStrategyIndex, mDateTimeStrategy); AddProperty(new BooleanPropertyBase("Static Log File Name:", "staticLogFileName", true)); AddProperty(new BooleanPropertyBase("Preserve Extension:", "preserveLogFileNameExtension", false)); mDatePatternIndex = Properties.Count; AddRemoveBasedOnMode(rollingStyle.SelectedMode, mDateModes, mDatePatternIndex, mDatePattern); mMaximumFileSizeIndex = Properties.Count; AddRemoveBasedOnMode(rollingStyle.SelectedMode, mMaximumFileSizeModes, mMaximumFileSizeIndex, mMaximumFileSize); AddProperty(new MaxSizeRollBackups()); mCountDirectionIndex = Properties.Count; AddRemoveBasedOnMode(rollingStyle.SelectedMode, mCountDirectionModes, mCountDirectionIndex, mCountDirection); }
public void DatePattern_ShouldBeAddedRemoved_BasedOnRollingMode(RollingMode mode, bool present) { mSut.Initialize(); RollingStyle rollingStyle = (RollingStyle)mSut.Properties.Single(p => p.GetType() == typeof(RollingStyle)); rollingStyle.SelectedMode = mode; Assert.AreEqual(present, mSut.Properties.FirstOrDefault(p => p.GetType() == typeof(DatePattern)) != null); }
public void Properties_ShouldNotBeDuplicated_WhenTheyAlreadyExist(RollingMode mode, int expectedCount) { mSut.Initialize(); RollingStyle rollingStyle = (RollingStyle)mSut.Properties.Single(p => p.GetType() == typeof(RollingStyle)); rollingStyle.SelectedMode = mode; Assert.AreEqual(expectedCount, mSut.Properties.Count); }
public void DateTimeStrategy_ShouldBeAddedRemoved_BasedOnRollingMode(RollingMode mode, bool present) { mSut.Initialize(); RollingStyle rollingStyle = (RollingStyle)mSut.Properties.Single(p => p.GetType() == typeof(RollingStyle)); rollingStyle.SelectedMode = mode; Assert.AreEqual(present, mSut.Properties.FirstOrDefault(p => p is StringValueProperty svp && svp.Name == "Date Time Strategy:") != null); }
/// <summary> /// Creates a file name based on the given <see cref="RollingStyle" /> /// <para>Examples:</para> /// <para>For <see cref="RollingStyle.Date"/> file name will be "yyyy-MM-dd" e.g. "2020-01-20"</para> /// </summary> /// <param name="rollingStyle">The <see cref="RollingStyle"/></param> /// <returns>File name</returns> private string CreateFileName(RollingStyle rollingStyle) { string fileName; switch (rollingStyle) { case RollingStyle.Date: fileName = DateTimeOffset.UtcNow.ToString("yyyy-MM-dd"); break; default: fileName = DateTimeOffset.UtcNow.ToString("yyyy-MM-dd"); break; } return(fileName); }
public void Properties_ShouldBeAddedToTheCorrectIndex_WhenAddedBasedOnRollingMode() { mSut.Initialize(); int dateIndex = mSut.Properties.IndexOf(mSut.Properties.Single(p => p.GetType() == typeof(DatePattern))); int staticIndex = mSut.Properties.IndexOf(mSut.Properties.Single(p => p.GetType() == typeof(StaticLogFileName))); RollingStyle rollingStyle = (RollingStyle)mSut.Properties.Single(p => p.GetType() == typeof(RollingStyle)); //Remove two properties rollingStyle.SelectedMode = RollingMode.Once; //Add them back rollingStyle.SelectedMode = RollingMode.Composite; Assert.AreEqual(dateIndex, mSut.Properties.IndexOf(mSut.Properties.Single(p => p.GetType() == typeof(DatePattern)))); Assert.AreEqual(staticIndex, mSut.Properties.IndexOf(mSut.Properties.Single(p => p.GetType() == typeof(StaticLogFileName)))); }
protected override void AddAppenderSpecificProperties() { base.AddAppenderSpecificProperties(); RollingStyle rollingStyle = new RollingStyle(Properties); rollingStyle.PropertyChanged += RollingStyleOnPropertyChanged; AddProperty(rollingStyle); AddProperty(new StaticLogFileName(Properties)); AddProperty(new PreserveExtension(Properties)); mDatePatternIndex = Properties.Count; AddRemoveBasedOnMode(rollingStyle.SelectedMode, mDatePatternModes, mDatePatternIndex, mDatePattern); mMaximumFileSizeIndex = Properties.Count; AddRemoveBasedOnMode(rollingStyle.SelectedMode, mMaximumFileSizeModes, mMaximumFileSizeIndex, mMaximumFileSize); AddProperty(new MaxSizeRollBackups(Properties)); mCountDirectionIndex = Properties.Count; AddRemoveBasedOnMode(rollingStyle.SelectedMode, mCountDirectionModes, mCountDirectionIndex, mCountDirection); }
public void SetUp() { mSut = new RollingStyle(); }
public void SetUp() { mSut = new RollingStyle(new ReadOnlyCollection <IProperty>(new List <IProperty>())); }
/// <summary> /// Constructs a new <see cref="RollingFileSink"/> /// </summary> /// <param name="directory">The directory used to write the log file to</param> /// <param name="rollingStyle">Rolling style used when creating new log files <see cref="RollingStyle"/></param> public RollingFileSink(DirectoryInfo directory, RollingStyle rollingStyle) { _directory = directory ?? throw new ArgumentNullException(nameof(directory)); _rollingStyle = rollingStyle; EnsureDirectoryExists(directory); }