我正在尝试使用 Nlog Refresh 1.0 为类库项目实现一个简单的日志。 从 dll 中实例化时,nlog 似乎不会创建日志文件。
还有其他解决方法吗?
我的配置文件是这样的:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="true">
<targets>
<target name="file" xsi:type="File" fileName="${basedir}/nlog.txt" />
<target name="console" xsi:type="Console" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="file" />
<logger name="*" minlevel="Info" writeTo="console" />
</rules>
</nlog>
我知道这个配置没有任何问题,因为它在一个 exe 项目中工作。
编辑: 只是为了澄清: 我无法访问使用我的 dll 作为插件的调用程序。调用程序实际上是 outlook,它使用我的 dll 作为插件。我想保留一个日志,它只与我的 dll 相关,与 outlook 本身无关。
最佳答案
您必须将 nlog.config 添加到使用 dll 的 exe 文件的位置!
编辑: 您不必修改 exe 文件,只需将 nlog.config 放在同一目录中,如果那不是选项,我想您将不得不从代码 https://github.com/nlog/NLog/wiki/Configuration-API 中配置它。
关于c# - 如何将 NLog 用于 DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5273377/