How to get an ILogger in OnApplicationStarted (IApplicationEventHandler)?
I'm trying to instantiate a DatabaseSchemaHelper in my OnApplicationStarted method. I have access to an UmbracoApplicationBase and an ApplicationContext.
public class Startup : IApplicationEventHandler
{
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
// ....
}
// ....
A required parameter in the constructor is an ILogger. I would also like to register an ILogger with my DI container.
I can't seem to find a public ILogger in docs or intellisense. UmbracoApplicationBase has one but it's marked as protected.
What is the right way to get an instance of ILogger here?
Hey Gary,
This is the recommended way of creating a DatabaseSchemaHelper.
public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
//Get the Umbraco Database context
var dbContext = applicationContext.DatabaseContext;
var logger = applicationContext.ProfilingLogger.Logger;
var dbSchemaHelper = new DatabaseSchemaHelper(dbContext.Database, logger, dbContext.SqlSyntax);
//Do awesome
}
How to get an ILogger in OnApplicationStarted (IApplicationEventHandler)?
I'm trying to instantiate a
DatabaseSchemaHelper
in myOnApplicationStarted
method. I have access to anUmbracoApplicationBase
and anApplicationContext
.A required parameter in the constructor is an
ILogger
. I would also like to register anILogger
with my DI container.I can't seem to find a public
ILogger
in docs or intellisense.UmbracoApplicationBase
has one but it's marked as protected.What is the right way to get an instance of
ILogger
here?Hey Gary,
This is the recommended way of creating a
DatabaseSchemaHelper
.Thanks,
Jamie
is working on a reply...