diff --git a/src/log4net.Tests/Appender/FileAppenderTest.cs b/src/log4net.Tests/Appender/FileAppenderTest.cs new file mode 100644 index 00000000..709aa5ee --- /dev/null +++ b/src/log4net.Tests/Appender/FileAppenderTest.cs @@ -0,0 +1,105 @@ +#region Apache License + +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to you under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#endregion + +using System.Xml; +using System; +using log4net.Appender; +using NUnit.Framework; +using log4net.Repository; +using log4net.Config; +using log4net.Util; + +namespace log4net.Tests.Appender; + +/// +/// Used for internal unit testing the class. +/// +[TestFixture] +public sealed class FileAppenderTest +{ + /// + /// Shuts down any loggers in the hierarchy, along with all appenders + /// + private static void Reset() + { + // Regular users should not use the clear method lightly! + LogManager.GetRepository().ResetConfiguration(); + LogManager.GetRepository().Shutdown(); + ((Repository.Hierarchy.Hierarchy)LogManager.GetRepository()).Clear(); + } + + /// + /// Any initialization that happens before each test can + /// go here + /// + [SetUp] + public void SetUp() => Reset(); + + /// + /// Any steps that happen after each test go here + /// + [TearDown] + public void TearDown() => Reset(); + + /// + /// Verifies that the property accepts a + /// + [Test] + public void FilenameWithPatternStringTest() + { + LogLog.LogReceived += LogReceived; + try + { + XmlDocument log4netConfig = new(); + log4netConfig.LoadXml(""" + + + + + + + + + + + + + + + + + + + +"""); + ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString()); + XmlConfigurator.Configure(rep, log4netConfig["log4net"]!); + ILog log = LogManager.GetLogger(rep.Name, "GeneralFileAppender"); + log.Info("Message"); + } + finally + { + LogLog.LogReceived += LogReceived; + } + + static void LogReceived(object? source, LogReceivedEventArgs e) => Assert.Fail(e.LogLog.Message); + } +} \ No newline at end of file