Skip to content

Make logging more friendly for docker #19818

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

Merged
merged 14 commits into from
Aug 1, 2025
Merged

Conversation

Migaroez
Copy link
Contributor

@Migaroez Migaroez commented Jul 29, 2025

Prerequisites

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

Description

With docker in mind, this PR sets out to make it easier to change the default logging behaviour shipped with Umbraco by

Testing

Copy link
Contributor

@AndyButland AndyButland left a comment

Choose a reason for hiding this comment

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

I've tested out the two scenarios.

Disabling the UmbracoFille sync in configuration prevents logging.

I could setup a custom log viewer source with the following:

using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Logging.Viewer;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Cms.Infrastructure.Logging.Serilog;
using Umbraco.Cms.Infrastructure.Services.Implement;

public class LogViewerComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.Services.AddUnique<ILogViewerService, CustomLogViewerService>();
        builder.Services.AddUnique<ILogViewerRepository, CustomLogViewerRepository>();
    }
}

public class CustomLogViewerRepository : LogViewerRepositoryBase
{
    public CustomLogViewerRepository(UmbracoFileConfiguration umbracoFileConfig)
        : base(umbracoFileConfig)
    {
    }

    protected override IEnumerable<ILogEntry> GetLogs(LogTimePeriod logTimePeriod, ILogFilter logFilter)
    {
        return new List<LogEntry>
        {
            new LogEntry
            {
                Level = Core.Logging.LogLevel.Information,
                MessageTemplateText = "This is a custom log entry: {Foo}",
                RenderedMessage = "This is a custom log entry: Bar",
                Timestamp = DateTime.UtcNow,
                Exception = null,
                Properties = new Dictionary<string, string?>
                    {
                        { "Foo", "Bar" },
                        { "MachineName", "MyServer" }
                    }.AsReadOnly()
            }
        };
    }
}

public class CustomLogViewerService : LogViewerServiceBase
{
    public CustomLogViewerService(
        ILogViewerQueryRepository logViewerQueryRepository,
        ICoreScopeProvider provider,
        ILogViewerRepository logViewerRepository)
        : base(
            logViewerQueryRepository,
            provider,
            logViewerRepository)
    {
    }

    protected override string RepositoryLoggerName => "MyLogger";

    public override Task<Attempt<bool, LogViewerOperationStatus>> CanViewLogsAsync(LogTimePeriod logTimePeriod)
        => Task.FromResult(Attempt.SucceedWithStatus(LogViewerOperationStatus.Success, true));
}

As noted on the docs PR, I created an implementation of the service too. This wasn't necessary, but I think it's better to have otherwise there's some unnecessary attempts to read files from disk in the CanReadLogs method of the default implementation.

@AndyButland AndyButland self-requested a review August 1, 2025 09:27
Copy link
Contributor

@AndyButland AndyButland left a comment

Choose a reason for hiding this comment

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

Have completed updates based on pending code review points.

Related docs PR is here: umbraco/UmbracoDocs#7271

@AndyButland AndyButland merged commit d9e7e9e into main Aug 1, 2025
24 of 25 checks passed
@AndyButland AndyButland deleted the v16/feature/logging-for-docker branch August 1, 2025 09:30
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.

2 participants