Files
Umbraco-CMS/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Logging/LoggingConfigurationTests.cs
Andy Butland 7c98af558d Allow for configuration of log file names (#19074)
* Added configuration for the log file name and format.

* Added unit test for LoggingConfiguration.

* Rely on configuration validation to verify supported log file format arguments.

* Fixed unit test failing on build pipeline.
2025-04-23 12:28:51 +02:00

26 lines
887 B
C#

using NUnit.Framework;
using Umbraco.Cms.Core.Logging;
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Logging;
[TestFixture]
public class LoggingConfigurationTests
{
[SetUp]
public void SetUp() => Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Production");
[Test]
public void Can_Get_Supported_Log_File_Name_Format_Arguments()
{
var config = new LoggingConfiguration("c:\\logs\\", "UmbracoLogFile_{0}_{1}..json", "MachineName,EnvironmentName");
var result = config.GetLogFileNameFormatArguments();
Assert.AreEqual(2, result.Length);
var expectedMachineName = Environment.MachineName;
var expectedEnvironmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Assert.AreEqual(expectedMachineName, result[0]);
Assert.AreEqual(expectedEnvironmentName, result[1]);
}
}