c# - 如何将 NLog 用于 DLL

标签 c# dll logging nlog

我正在尝试使用 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/

相关文章:

c++ - 使用 "::"字符串名称在 C++ 中调用 DLL 导出

ruby-on-rails - 在 Rails 3 中格式化日志消息的更好方法?

mysql - 如何通过 : log and anlyze clicks, 页面浏览量和 session 数来优化转化

c# - C# 对象是否知道更具体类的类型?

c# - Linq 查询未在 MVC 应用程序中转换为字符串

c# - 转换为字符串与调用 ToString

c# - 帮助使用 FluentNHibernate 创建 ColumnName 约定

dll - PCL 库和类似的 File.Exists 函数

python - 我可以在 64 位 python 中使用 32 位 dll 或 exe 吗?

python - 我的 Django 应用程序中由 uwsgi 启动的日志记录在哪里?