0

We're currently on Sitecore 9.1 and recently migrated onto Sitecore's dependency injection framework in order to get Sitecore Forms to work correctly. The transition seemed to go smoothly, however now Sitecore is no longer outputting logs to the App_Data/logs folder. The only thing that was changed was that instead of using SimpleInjector to register our dependencies we began registering them as follows within Sitecore's framework:

Configuration:

<services>
  <configurator type="MyNamespace.Pipelines.RegisterDependencies, MyNamespace." />
</services>

Code:

namespace MyNamespace
{
    public class RegisterDependencies : IServicesConfigurator
    {
        public void Configure(IServiceCollection serviceCollection)
        {
            serviceCollection.AddTransient(typeof(IAnalyticsService), typeof(AnalyticsService));
        }
    }
}

I can't seem to figure out why this change would break Sitecore's logging functionality. When debugging our code I can still see the ILogger declarations resolving correctly:

private ILog _logger;
protected ILog Logger
{
    get
    {
        if (_logger == null)
            _logger = Sitecore.Diagnostics.LoggerFactory.GetLogger(Foundation.Logging.Constants.Logger.Feature);
        return _logger;
    }

}

I've tried adding the following setting to our log4net appender declarations:

<immediateFlush value="true"/>

And I have also tried manually setting the buffer size of the appender in a given logger to 1 to try to force it to flush:

var logger = Logger.Logger as Logger;
if (logger != null)
{
    foreach (IAppender appender in logger.Appenders)
    {
        var buffered = appender as BufferingAppenderSkeleton;
        if (buffered != null)
        {
            buffered.BufferSize = 1;
        }
    }
}

Neither steps have caused any logs to be produced. Any thoughts on what might be going on here? Thanks for the help!

1 Answer 1

0

Finally figured it out. I narrowed down the error to a single processor:

public class RegisterDependencies : IServicesConfigurator
{
    private ILog _logger;

    protected ILog Logger
    {
        get
        {
            if (_logger == null)
                _logger = Sitecore.Diagnostics.LoggerFactory.GetLogger("MyLogger");
            return _logger;
        }
    }

    public void Configure(IServiceCollection serviceCollection)
    {
        Logger.Info("Language: Registering Language Dependencies");
        serviceCollection.AddTransient<LanguageController>();
        serviceCollection.AddTransient(typeof(ILanguageRepository), typeof(LanguageRepository));
        serviceCollection.AddTransient(typeof(ILanguageService), typeof(LanguageService));
    }
}

The logging statements within this processor were knocking out all Sitecore logging when we migrated onto Sitecore's DI framework. It's strange because the Logger object was resolving correctly but calling into its Info and Debug functions must have been causing errors behind the scenes. We have other RegisterDependencies processors where we resolve an instance of ILog but never make calls to actually log anything and those work fine. After removing the logging statements everything is working now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.