Allow for configuration of log file names#19074
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces configurable log file naming, allowing the use of environment-specific values (e.g. MachineName or EnvironmentName) to address issues with log file cleanup on Umbraco Cloud. Key changes include updating the logging configuration to accept a customizable file name format with comma-delimited arguments, extending tests to verify proper behavior and validation, and wiring the new configuration settings throughout the logging and dependency injection setup.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/Logging/LoggingConfigurationTests.cs | Added unit tests to verify log file name format argument resolution. |
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/Configuration/Models/Validation/LoggingSettingsValidatorTests.cs | Added tests to validate the new logging settings including error cases. |
| src/Umbraco.Web.Common/Extensions/ServiceCollectionExtensions.cs | Updated logging configuration instantiation to pass in custom format options. |
| src/Umbraco.Infrastructure/Logging/Serilog/UmbracoFileConfiguration.cs | Modified path resolution to use the new file name format and arguments. |
| src/Umbraco.Infrastructure/Logging/Serilog/LoggerConfigExtensions.cs | Updated logger configuration to use the customizable log file path. |
| src/Umbraco.Core/Logging/LoggingConfiguration.cs | Extended the configuration class to support multiple file name format arguments with a helper to resolve values. |
| src/Umbraco.Core/Logging/ILoggingConfiguration.cs | Expanded the interface to expose the file name format and its arguments. |
| src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs | Registered the logging settings validator into the dependency injection pipeline. |
| src/Umbraco.Core/Configuration/Models/Validation/LoggingSettingsValidator.cs | Implemented validation logic to ensure only supported file name format arguments are used. |
| src/Umbraco.Core/Configuration/Models/LoggingSettings.cs | Added properties for file name format and its arguments with default values. |
bergmania
approved these changes
Apr 22, 2025
5 tasks
Zeegaan
approved these changes
Apr 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
This PR adds some additional options for configuring the file name used for Umbraco logging.
The request has come from Umbraco Cloud, as they find with the existing default of logging with files containing the machine name, as they found these did not get cleaned up when the machine name changes due to some moving of resources at Azure. The thinking was that it would be better to use the environment name for the Cloud case.
There could be other situations though, like when load balancing, that the machine name is useful. Perhaps as now, or in conjunction with the environment name,
To support this I've added two additional configuration settings:
This allows setting of a custom file name format, along with the arguments that should be included as a comma delimited list.
Currently only two arguments are supported:
MachineName- outputs the machine nameEnvironmentName- outputs the environment name ("Development", "Production" etc.)Any other values will be rejected in the validation of the application configuration.
Testing
Apply something along the lines of the configuration above, and verify the logs written to the default location of
umbraco/Logshave the expected file name.Create some dummy files for previous dates and verify they get removed on start-up when you have applied the appropriate configuration (the default with no configuration is to remove files older than 31 days).
Remove custom logging and verify that log files are written with the file names as per the existing behaviour.