【发布时间】:2011-10-15 09:49:38
【问题描述】:
您好,我尝试在 caliburn micro 中使用 Nlog,我已使用本教程 http://buksbaum.us/2010/08/08/how-to-do-logging-with-caliburn-micro/。
首先我定义了 Nloagger 类,这里是:
public class NLogLogger : ILog
{
#region Fields
private readonly NLog.Logger _innerLogger;
#endregion
#region Constructors
public NLogLogger(Type type)
{
_innerLogger = NLog.LogManager.GetLogger(type.Name);
}
#endregion
#region ILog Members
public void Error(Exception exception)
{
_innerLogger.ErrorException(exception.Message, exception);
}
public void Info(string format, params object[] args)
{
_innerLogger.Info(format, args);
}
public void Warn(string format, params object[] args)
{
_innerLogger.Warn(format, args);
}
#endregion
}
我修改了 MEF 引导程序:
#region Constructors
public MefBootStrapper()
: base()
{
_msgBox = new MessageBoxes();
_doHandle = true;
}
static MefBootStrapper()
{
LogManager.GetLog = type => new NLogLogger(type);
}
#endregion
以及最后修改的 app.config
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File" fileName="file.txt" />
</targets>
<rules>
<logger name="*" minlevel="Error" writeTo="logfile" />
</rules>
</nlog>
</configuration>
这对我来说真的很愚蠢,但我现在不知道如何在 View 模型类中使用记录器,其次我想知道是否可以使用 NLog 记录到 XML 文件。
感谢您的支持
【问题讨论】:
标签: wpf xml mef nlog caliburn.micro