Skip to content

Keep Current.Logger = {Umbraco.Core.Logging.Serilog.SerilogLogger} unless specifically changed #6774

Description

@hfloyd

I'm not sure if this is a bug or a feature request... So feel free to reclassify...

In my project, I have a custom "WebControllerBase : SurfaceController, IRenderMvcController" and then a "public class DefaultController : WebControllerBase" which wraps the Model with some extra stuff and swaps the View. (This is set to run for all page requests via a "Startup : IUserComposer" with composition.SetDefaultRenderMvcController(typeof(DefaultController));)

The problem I have noticed is that this changes the type of Current.Logger from {Umbraco.Core.Logging.Serilog.SerilogLogger} (which DOES log as expected to Serilog, and is visible in the LogViewer) to {Umbraco.Core.Logging.DebugDiagnosticsLogger} (which DOES NOT log as expected).

I'm not exactly sure why this gets changed, or where/how I could set it back to {Umbraco.Core.Logging.Serilog.SerilogLogger}. I want to be able to use logging in my View files.

Bug summary

By using a custom controller, and without explicitly implementing a different logger, default logging via Current.Logger stops working. There are no compilation errors or warnings about this logged anywhere, it just doesn't log anything to Serilog.

Steps to reproduce

  1. Create a custom controller "DefaultController: SurfaceController, IRenderMvcController". It doesn't need to do anything specific that is different from default behavior. Ex:
public override ActionResult Index(ContentModel model)
       {
           return base.CurrentTemplate(model);
       }
  1. Make it the default controller via an IUserComposer with composition.SetDefaultRenderMvcController(typeof(DefaultController));
  2. Create a View for a Doctype, Add some code to do some test logging:
@using Umbraco.Core.Composing
@using Umbraco.Core.Logging
@inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
@{
    Layout = null; 
    //Test logging
    var page = Umbraco.AssignedContentItem.Name;
    var tempError = new Exception("Just a fake error!");
    Current.Logger.Error<UmbracoViewPage<IPublishedContent>>(tempError, "1 - TEST ERROR on '{Page}'", page);
     Current.Logger.Info<UmbracoViewPage<IPublishedContent>>("2 - TEST on '{Page}'", page);
}
  1. Run the page.
  2. Check the LogViewer. You won't see your log entries.

Expected result

I would expect that unless I specifically set a different logger, that all my Controllers and Views (and Models) would utilize {Umbraco.Core.Logging.Serilog.SerilogLogger} so that logging works as expected.

Actual result

Custom log messages are not logged properly. Standard Umbraco.Core logs are still generated.

Related Forum Posts

Metadata

Metadata

Assignees

No one assigned

    Labels

    state/needs-investigationThis requires input from HQ or community to proceedstatus/staleMarked as stale due to inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions