0

我只是想起床并习惯使用 Prism,在我的引导程序中,我有:

public class Bootstrapper : UnityBootstrapper
{

    private readonly EnterpriseLibraryLoggerAdapter _logger =  new EnterpriseLibraryLoggerAdapter();  

    protected override void InitializeShell()
    {
        base.InitializeShell();

        Application.Current.MainWindow = (Shell)this.Shell;
        Application.Current.MainWindow.Show();
    }

    protected override DependencyObject CreateShell()
    {
        return this.Container.Resolve<Shell>();
    }

    protected override ILoggerFacade CreateLogger()
        {
              return _logger; 
        }

对于我的 App OnStartup:

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        Bootstrapper bootstrapper = new Bootstrapper();
        bootstrapper.Run();
    }
}

和日志适配器

public class EnterpriseLibraryLoggerAdapter : ILoggerFacade
{
    #region ILoggerFacade Members

    public void Log(string message, Category category, Priority priority)
    {
        Logger.Write(message, category.ToString(), (int)priority); // <--Blows up here 
    }

    #endregion
}

当引导程序运行时,它会命中 Logger.Write 并抛出异常:

The type LogWriter does not have an accessible constructor.

我正在关注 StockTraderRI 示例应用程序。我在某处错过了注册吗?

4

1 回答 1

0

将配置移至我的引导程序构造函数,一切似乎都在工作

 var builder = new ConfigurationSourceBuilder();
        builder.ConfigureLogging()
            .WithOptions
            .DoNotRevertImpersonation()
            .LogToCategoryNamed("Debug")
            .SendTo.FlatFile("Basic Log File")
            .FormatWith(new FormatterBuilder()
                            .TextFormatterNamed("Text Formatter")
                            .UsingTemplate(
                                "Timestamp: {timestamp}{newline}Message: {message}{newline}Category: {category}{newline}"))
            .ToFile("core.log")
            .SendTo.RollingFile("Rolling Log files")
            .RollAfterSize(1024)
            .ToFile("RollingTest.log")
            .LogToCategoryNamed("General")
                .WithOptions.SetAsDefaultCategory()
                .SendTo.SharedListenerNamed("Basic Log File");

        var configSource = new DictionaryConfigurationSource();
        builder.UpdateConfigurationWithReplace(configSource);
        EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
于 2013-03-04T05:21:06.943 回答