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
- 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);
}
- Make it the default controller via an
IUserComposer with composition.SetDefaultRenderMvcController(typeof(DefaultController));
- 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);
}
- Run the page.
- 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
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
IUserComposerwithcomposition.SetDefaultRenderMvcController(typeof(DefaultController));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