我是NLog的新手,已经选择将它添加到我的ServiceStack(4.0.44)Web服务中,但它不能正常工作,因为我总是以NullDebugLogger结束。配置带有ServiceStack的NLog不是NullDebugLogger
我
的Global.asax
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
LogManager.LogFactory = New NLogFactory()
Dim appHost As New MyAppHost
appHost.Init()
End Sub
我还手动添加一个NLog.config文件记录到调试器
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="true"
internalLogLevel="Trace" internalLogFile="c:\temp\nlog-internal.log" >
<targets>
<!-- log to the debugger -->
<target xsi:type="Debugger" name="debugger" layout="${logger}::${message}"/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="debugger" />
</rules>
</nlog>
终于在我的课我有以下
public class MyClass
{
public static ILog Log;
public MyClass()
{
Log = LogManager.GetLogger(typeof(MyClass));
}
public void LogSomething()
{
Log.Debug("Starting to LogSomething");
}
}
当我调试时,我的类中的Log对象显示为ServiceStack.Logging.NullDebugLogger,我相信这是默认的,但我无法弄清楚如何将其更改为我可以使用的东西。我确信我错过了一些简单的东西,但无法弄清楚它是什么。我的Web服务在不同的项目中(在相同的解决方案中),这就是为什么我的Global.asax是VB并且类是C#。我也没有参考web.config到NLog.config,但我认为Nlog无论如何选择了。
谢谢Mythz我会看看那个 – Steve