question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nul800sebastiaancommented, Oct 21, 2019

Well that is a good find! I guess by injecting a specific logger you get the one you were expecting instead of DebugDiagnosticsLogger (which, I believe, is the miniprofiler logger).

I am not sure if this intentional behavior, I’ll need to ask around. But if it is then it should be documented.

0reactions
umbrabotcommented, Jul 7, 2022

Hiya @hfloyd,

Just wanted to let you know that we noticed that this issue got a bit stale and might not be relevant any more.

We will close this issue for now but we’re happy to open it up again if you think it’s still relevant (for example: it’s a feature request that’s not yet implemented, or it’s a bug that’s not yet been fixed).

To open it this issue up again, you can write @umbrabot still relevant in a new comment as the first line. It would be super helpful for us if on the next line you could let us know why you think it’s still relevant.

For example:

@umbrabot still relevant This bug can still be reproduced in version x.y.z

This will reopen the issue in the next few hours.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug with Current.Logger - or maybe I'm using it wrong
Core.Composing; using Umbraco.Core.Logging; using Umbraco. ... Does not log to serilog - goes to DebugDiagnosticsLogger Current.Logger.
Read more >
Serilog Best Practices - Ben Foster
Serilog is a structured logging library for Microsoft . ... HTTP Logging; Avoid excessive production logging; Create log specific objects ...
Read more >
c# - How to prevent Serilog from logging every little step as ...
NET host with the level Information and thus Serilog receives them as Information ... Log.Logger = new LoggerConfiguration() .MinimumLevel.
Read more >
Umbraco V8 – Swapping Log4Net for Serilog with this ...
So in this blog post I will perform a switcheroo trick and swap the logging framework used in Umbraco V8 from Log4Net to...
Read more >
Setting up Serilog in .NET 6 - Structured Blog
Serilog has an unbeatable selection of output destinations (sinks), and its ability to enrich, route, filter, and format structured log events ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found