Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在用户控制中使用NLog_C#_.net_Logging_User Controls_Nlog - Fatal编程技术网

C# 在用户控制中使用NLog

C# 在用户控制中使用NLog,c#,.net,logging,user-controls,nlog,C#,.net,Logging,User Controls,Nlog,我正在尝试将NLog用于我的WindowsFormsControl库,但它不起作用。有没有办法提供使用my 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">

我正在尝试将NLog用于我的WindowsFormsControl库,但它不起作用。有没有办法提供使用my 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无法写入文件的原因是因为缺少nlog.config,这听起来不合理啊?但就是这样,您必须将Nlog.config复制到应用程序文件夹,而不是您的DLL文件夹,在您的情况下,它是包含您的UserControl DLL:使用的应用程序的文件夹!
如果无法使用我的解决方案解决问题,请与我联系:tanh1989@gmail.com

“不工作”不是错误描述。你有什么问题?此外,请在下面显示您的日志代码i find decision:在应用程序中创建NLog实例(而不是在.dll中),并在dll中简单地使用它。不要在您的控件中创建nlog安装!