Skip to content

Allow for configuration of log file names #19074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: v16/dev
Choose a base branch
from

Conversation

AndyButland
Copy link
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

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:

  "Logging": {
    "FileNameFormat": "CustomUmbracoTraceLog.{0}.{1}..json",
    "FileNameFormatArguments": "MachineName,EnvironmentName"
  },

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 name
  • EnvironmentName - 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/Logs have 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.

@Copilot Copilot AI review requested due to automatic review settings April 17, 2025 08:12
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@AndyButland AndyButland changed the title V16/feature/configure log file name Allow for configuration of log file names Apr 17, 2025
@AndyButland AndyButland requested a review from bergmania April 17, 2025 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant