I am looking into Umbraco 9 and couldn't figure out how to log errors to the error log in the same way we used to do for Umbraco 8.
Did they drop the Umbraco.Core.Logging?
Does anyone have an example of how to do error logging the expected way in Umbraco 9?
Before it was something like this. But with Umbraco 9 I am not even sure how to inject the logger into my controllers. I am guessing dependency injection has changed to be more inline with .Net Core'sway of doing this.
Hi David - yes, Umbraco.Core.Logging has been removed, and as you suspected, Umbraco's logging has been aligned to be inline with how it's done generally in .NET Core.
You should find you can inject ILogger<SiteService> and then be able to call methods like LogInformation() on it.
using System;
using Microsoft.Extensions.Logging;
namespace MyNamespace
{
public class MyClass
{
private readonly ILogger<MyClass> _logger;
public MyClass(ILogger<MyClass> logger)
{
_logger = logger;
}
public void MyMethod()
{
_logger.LogError(new Exception(), "A message");
}
}
}
Umbraco 9 Correct way to use Umbraco Error Logger
Hi All,
I am looking into Umbraco 9 and couldn't figure out how to log errors to the error log in the same way we used to do for Umbraco 8.
Did they drop the Umbraco.Core.Logging?
Does anyone have an example of how to do error logging the expected way in Umbraco 9?
Before it was something like this. But with Umbraco 9 I am not even sure how to inject the logger into my controllers. I am guessing dependency injection has changed to be more inline with .Net Core'sway of doing this.
Kind Regards
David
Hi David - yes,
Umbraco.Core.Logging
has been removed, and as you suspected, Umbraco's logging has been aligned to be inline with how it's done generally in .NET Core.You should find you can inject
ILogger<SiteService>
and then be able to call methods likeLogInformation()
on it.Andy
Thanks Andy
We use Microsoft's logging abstraction..
You can inject a generic logger:
Thanks Bjarke
For future reference.
I added short blog article here for anyone interested. https://www.umbrajobs.com/blog/posts/2021/june/the-new-way-to-handle-error-logging-in-umbraco-9/
You will also find a number of 'Umbraco 9 Getting Up And Running' articles here. Just some basic stuff to help everyone get up to speed. https://www.umbrajobs.com/blog/categories/umbraco-9-getting-up-and-running/
Hope some of these articles help.
Regards
David
is working on a reply...