【问题标题】:Using NLog in UserControl在用户控件中使用 NLog
【发布时间】:2012-09-24 09:32:03
【问题描述】:

我正在尝试将 NLog 用于我的 WindowsFormsControlLibrary,但它不起作用。有没有办法提供登录使用我的 Control.dll 的 .exe 应用程序?

 <?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">

  <!-- make sure to set 'Copy To Output Directory' option for this file -->
  <!-- go to http://nlog-project.org/wiki/Configuration_file for more information -->

  <targets>
    <target name="file" xsi:type="File" fileName="${basedir}/${shortdate}/file.txt"
     layout="${stacktrace} ${longdate} ${message}" />
  </targets>

  <rules>
    <logger name="*" minlevel="Trace" writeTo="file" />
  </rules>
</nlog>

【问题讨论】:

  • “不起作用”不是错误描述。你有什么问题?此外,请出示您的日志记录代码
  • 我发现以下决定:在您的应用程序中创建 NLog 实例(而不是在 .dll 中)并在您的 dll 中简单地使用它。不要在控件中创建 nlog 实例!

标签: c# .net logging user-controls nlog


【解决方案1】:

我今天早上也遇到了这个问题。也许,我的解决方案为时已晚,但我会在这里发布以防有人需要。 nlog 无法写入文件的原因是因为缺少 Nlog.config,这听起来不合理啊?但就是这样,您必须将 Nlog.config 复制到 application 文件夹而不是您的 DLL 文件夹,在您的情况下,它是包含使用您的 UserControl dll 的应用程序的文件夹 :)! 如果您无法通过我的解决方案解决问题,请与我联系:tanh1989@gmail.com

【讨论】:

    猜你喜欢
    • 2013-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多