我目前正在使用C#开发一个新的Prism项目,并希望在我的Bootstrapper类中创建一个NLog Logger.不幸的是,无论我做什么都拒绝建立,告诉我......
由于其保护级别,"Logger.Logger()"无法访问.
我的代码片段列在下面......
namespace PrismTemplate { public class Bootstrapper : UnityBootstrapper { #region Method Overrides protected override ILoggerFacade CreateLogger() { //ILoggerFacade logger = new NLogLogger(); ILoggerFacade logger = new Logger(); logger.Log("Prism Template Logger was Created.", Category.Info, Priority.None); return logger; //return new Logger(); //return null; } protected override DependencyObject CreateShell() { return new ShellWindow(); } protected override void InitializeShell() { base.InitializeShell(); ///Assign the shell which is a window to the apps main window, and show it App.Current.MainWindow = (Window)this.Shell; App.Current.MainWindow.Show(); } #endregion Method Overrides } }
我在Visual Studio中通过Nuget下载了Prism和NLog.任何帮助攻击这个问题的人都会非常感激.
谢谢,
Tesnich
由于记录器的配置繁重,NLog选择将日志创建职责委托给密封的LogManager类.
您可以使用任一来获取实例:
LogManager.GetCurrentClassLogger()
要么
LogManager.GetLogger(string name)