So, I'm not sure if I am doing something wrong or this is a bug...
If I have a basic Template inheriting UmbracoViewPage... why don't my log messages appear in the LogViewer?
Here is some relevant test code:
@using MySite.Models
@using Umbraco.Core.Composing;
@using Umbraco.Core.Logging;
@inherits UmbracoViewPage<ArticlesListing>
@{
Layout = "MasterSitePage.cshtml";
//Test logging
var page = Umbraco.AssignedContentItem.Name;
var tempError = new Exception("Just a fake error!");
Current.Logger.Error<UmbracoViewPage<ArticlesListing>>(tempError, "TEST ERROR in ArticlesListing on '{Page}'", page);
}
If I visit a page that uses this template, then check the LogViewer, it is showing no errors logged. Searching for the specific message doesn't turn up anything either.
I don't know if Cloud does any specific. You could try reaching out to their support.
Does it work if you remove the UmbracoViewPage part when writing to the log? As it's in the Umbraco namespace, it could be that they intercept that on Cloud.
Btw - my solution is just a test site I set up the other day when 8.2 was released the other day, so it's pretty standard.
SO, I did a file comparison between my site and a download of 8.2 for the Releases page.
No significant config or file differences which might indicate something having to do with Serilog...
The only thing I can imagine is that since I have a custom controller intercepting all page requests, somehow that is interfering with logging... But I'm not quite sure how it would. or what I'd need to do about it.
As a test, I removed my custom dll which intercepts the page requests and set a breakpoint in a stripped-down template file, at the line 'Current.Logger.Error...'
Okay, I've managed to fix this for my project. I don't totally understand why this fixes it, but if I add private logger variables to my custom Controllers, the Views now log correctly.
public abstract class WebControllerBase : SurfaceController, IRenderMvcController
{
private readonly ILogger _logger;
public WebControllerBase(ILogger logger)
{
_logger = logger;
}
...
}
public class DefaultController : WebControllerBase
{
private readonly ILogger _logger;
public DefaultController(ILogger logger) : base(logger)
{
_logger = logger;
}
public override ActionResult Index(ContentModel model)
{...}
}
We experience the same problem, only when a document type has a custom controller, errors are reported via the logger. Are you still using the above method or have you found another solution?
Hi,
I haven't built any new Umbraco 8 sites in awhile. I assume that is still the best method to use for Umbraco 8. For versions 9+, use dependency injection.
Use of Current.Logger in UmbracoViewPage, etc?
So, I'm not sure if I am doing something wrong or this is a bug...
If I have a basic Template inheriting UmbracoViewPage... why don't my log messages appear in the LogViewer?
Here is some relevant test code:
If I visit a page that uses this template, then check the LogViewer, it is showing no errors logged. Searching for the specific message doesn't turn up anything either.
I have reviewed the current documentation at https://our.umbraco.com/documentation/getting-started/Code/Debugging/Logging/ and have looked at another forum question (also about Logging issues - but their specific question is about Custom components - https://our.umbraco.com/forum/umbraco-8/97996-bug-with-currentlogger-or-maybe-im-using-it-wrong)
Has anyone gotten logging to work in V8? If so, what am I missing here?
Hi Heather,
What version of Umbraco 8 are you using? I just tried your code in my 8.2 solution, and it works fine.
I've tried it in an 8.2 site and in an 8.1.5 site.
Do you know of anything which might somehow interfere with logging in general?
I see all the standard Umbraco-provided log messages, but nothing that I have added...
(These are Umbraco Cloud sites - if that makes any difference.)
I don't know if Cloud does any specific. You could try reaching out to their support.
Does it work if you remove the
UmbracoViewPage
part when writing to the log? As it's in the Umbraco namespace, it could be that they intercept that on Cloud.Btw - my solution is just a test site I set up the other day when 8.2 was released the other day, so it's pretty standard.
Thanks, Anders, I'll try your suggestions.
SO, I did a file comparison between my site and a download of 8.2 for the Releases page.
No significant config or file differences which might indicate something having to do with Serilog...
The only thing I can imagine is that since I have a custom controller intercepting all page requests, somehow that is interfering with logging... But I'm not quite sure how it would. or what I'd need to do about it.
As a test, I removed my custom dll which intercepts the page requests and set a breakpoint in a stripped-down template file, at the line 'Current.Logger.Error...'
Upon running the page and hitting the breakpoint:
I then DID see the log messages in the LogViewer.
I re-added my custom dll, and checked the breakpoint again -
So, somewhere along the way, "Logger" changed type.
Okay, I've managed to fix this for my project. I don't totally understand why this fixes it, but if I add private logger variables to my custom Controllers, the Views now log correctly.
Hi Heather,
We experience the same problem, only when a document type has a custom controller, errors are reported via the logger. Are you still using the above method or have you found another solution?
Hi, I haven't built any new Umbraco 8 sites in awhile. I assume that is still the best method to use for Umbraco 8. For versions 9+, use dependency injection.
is working on a reply...