EntLib5:登录应用程序块未记录到事件日志(例外:无法构造 LogWriter 类型)-任何人都可以帮忙吗?

2024-06-26

你好呀,

我刚刚设置了 Enterprise Library 5 的日志记录应用程序块部分。我认为我已经完成了正确的操作,但它没有记录到事件日志,它在写入方法上出错并给出了以下异常。

    The type LogWriter cannot be constructed. 
         You must configure the container to supply this value.

谁能帮我检查一下或告诉我我缺少什么..

首先,我在 Windows 7 中运行 winforms 应用程序。

这是我创建日志的方法,您可以看到 write 方法。

public class Logger : ILogger
{
    public void SendTest(string test)
    {
        LogEntry log = new LogEntry();
        log.EventId = 300;
        log.Message = test;
        log.Categories.Add("testing");
        log.Severity = TraceEventType.Information;
        log.Priority = 5;
        Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(log);

    }
}

我的所有配置都是使用 entlib5 编辑器构建的,而不是手动构建的。并确认 si entlib.config 所在的路径

    filePath="C:\myapp\entlib.config" />

这是我的 app.config,它指向我的 entlib.config

<?xml version="1.0"?>
<configuration>
<configSections>
    <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<enterpriseLibrary.ConfigurationSource selectedSource="System Configuration Source">
    <sources>
        <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <add name="File-based Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            filePath="C:\myapp\entlib.config" />
    </sources>
    <redirectSections>
        <add sourceName="File-based Configuration Source" name="Redirected Section" />
    </redirectSections>
</enterpriseLibrary.ConfigurationSource>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>

这是我的 entlib.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    </configSections>
    <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
        <listeners>
            <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                source="Enterprise Library Logging" formatter="Text Formatter"
                log="" machineName="." traceOutputOptions="None" />
        </listeners>
        <formatters>
            <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
                name="Text Formatter" />
        </formatters>
        <categorySources>
            <add switchValue="All" name="General">
                <listeners>
                    <add name="Event Log Listener" />
                </listeners>
            </add>
        </categorySources>
        <specialSources>
            <allEvents switchValue="All" name="All Events" />
            <notProcessed switchValue="All" name="Unprocessed Category" />
            <errors switchValue="All" name="Logging Errors &amp; Warnings">
                <listeners>
                    <add name="Event Log Listener" />
                </listeners>
            </errors>
        </specialSources>
    </loggingConfiguration>
</configuration>

EDIT该问题已使用新的 app.config 进行了更新,包括

<redirectSections>
    <add sourceName="File-based Configuration Source" name="Redirected Section" />
</redirectSections>

我仍然收到错误。

 Activation error occured while trying to get instance of type

日志写入器,键“”

和内部异常是

依赖关系解析失败, 类型= \"Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter\", 名称 = \"(无)\"。\r\n异常 发生时间:同时 正在解决。\r\n异常是: InvalidOperationException - 类型 无法构造 LogWriter。你 必须配置容器来供应 这 值。\r\n-------------------------------------------------------- ---\r\n异常发生时, 容器为:\r\n\r\n 正在解析 Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(无)\r\n"}

我使用 EntLib 配置器创建这两个文件。

我接受了默认的 entlib.config,因为它似乎包含了 EventLog 侦听器。

EDIT

这是我在 entlib.config 文件中的行,日志为空 - 呃,这是正确的吗?

    <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        source="Enterprise Library Logging" formatter="Text Formatter"
        log="" machineName="." traceOutputOptions="None" />

EDIT

我的 Logger.write 在 dll 中,但我的 app.config / entlib.config 在 winforms 应用程序中。winforms 应用程序引用了我在其中写入日志的 dll 项目。

dll和winforms都有参考

   Microsoft.Practices.EnterpriseLibrary.Logging

并且还使用统一,具有

   Microsoft.Practices.Unity

   Microsoft.Practices.Unity.Interception

Martin,您已经创建了一个基于文件的配置源,但尚未将日志记录部分重定向到它。

将以下内容添加到 enterpriseLibrary.ConfigurationSource 节点内的 App.config 中:

<redirectSections>
      <add sourceName="File-based Configuration Source" name="loggingConfiguration" />
</redirectSections>

此外,我推荐来自企业图书馆5.0实践实验室 http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8cd377-5522-4f45-a024-44a6ca5111ec放。它涵盖了这种情况以及更高级的场景。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

EntLib5:登录应用程序块未记录到事件日志(例外:无法构造 LogWriter 类型)-任何人都可以帮忙吗? 的相关文章

随机推荐

  • 如何在 Android 中没有视频视图的情况下从 URL 获取视频长度(以毫秒为单位)?

    我正在 Android 中制作一个媒体播放器 我需要一个代码来获取视频长度而不使用视频视图 我在堆栈溢出中看到了很多页面 但每个页面都用于显示如何在视频视图中获取视频的长度 但我需要没有视频视图 你可以使用媒体元数据检索器 http dev
  • Windows 安装程序 (C#) 错误代码 2869

    我在 VS 2005 中有一个项目 其中有一个控制台应用程序和一个与安装该应用程序关联的安装项目 我在控制台应用程序中还有一个安装程序类 安装项目将使用它在安装前进行一些验证 这些任务正在检查数据库连接字符串并检查某些目录位置以确保它们在安
  • 客户端和服务器之间的安全连接

    我正在开发一个服务器组件 它将为嵌入式客户端的请求提供服务 这也在我的控制之下 现在一切都是测试版 安全性是这样的 客户端通过 https 发送用户名 密码 服务器返回访问令牌 客户端使用自定义标头中的访问令牌通过 http 发出进一步请求
  • SQL Server到Mysql迁移(使用Mysql Workbench)数据传输错误

    我正在使用 Mysql Work bench 6 3 将数据库从 MS Sql server 2008 迁移到 Mysql 在 批量数据传输 期间出错并出现以下警告 这种情况仅发生在像 varchar char 这样的列类型上 当我尝试使用
  • 将阿拉伯语文本导出为图像

    我有一堆 UTF 8 格式的阿拉伯文本 我尝试显示此设备的设备不支持显示阿拉伯语文本 因此 我需要将文本转换为图像 我想将每行文本保存为具有特定宽度的图像 我还需要使用特定的字体 做这个的最好方式是什么 有人知道这里有一个有用的工具吗 到目
  • 如何使 Mercurial 按提交日期对“hg log”的输出进行排序?

    我怎样才能使 Mercurial 排序输出hg log按提交日期 输出似乎是按我将提交拉入存储库的日期而不是提交的时间排序的 您需要使用转速集 hg log r sort all date 如果您想首先查看最近的提交 请执行以下操作 hg
  • 创建将一把小提琴按色调分割的小提琴图的正确方法是什么?

    创建将一把小提琴分开的小提琴图的正确方法是什么hue 我尝试了不同的方法 似乎唯一的方法是创建一个为数据集中的每个条目共享相同值的功能 并将该功能的名称传递为x fig plt figure figsize 20 8 fig add sub
  • 使用 git 合并两个文件夹

    我正在和一些以前从未使用过 git 的人一起开发一个项目 由于不了解 git 的功能 他们创建了该项目的两个版本 开发版本和生产版本 这两个版本都存在于当前环境中 更复杂的是 除了旧的开发文件夹之外 另一个用户还创建了这些文件夹 所以项目目
  • 在 Rails 中,如何创建用户组作为另一个关联,例如“成员”?

    我正在尝试在两个现有模型之间创建特殊关系 User and Dwelling A Dwelling只有一个所有者 Dwelling belongs to user User has one dwelling 在创建时 但其他用户可以添加到此
  • 显示进度的脚本?

    当我的 python 脚本处理大文件时 我想向用户显示进度 我见过脚本印刷 在 shell 中的同一光标位置显示进度 我怎样才能在Python中做到这一点 你应该使用python 进度条 http code google com p pyt
  • Scipy odeint 非负解

    显然 从 ODE 求解器获得非负解并非易事 https stackoverflow com questions 6977107 solving a delay differential equation dde system constra
  • git 列出所有可用命令

    有没有命令可以显示 GIT 中所有可用命令的列表 有git help但它显示 usage git version exec path
  • 系统.安全.加密与 PCLCrypto

    我们正在删除系统中的许多共享功能并将其移植到 PCL 库中 我在使用 PCLCrypto 时遇到问题 我正在获取数据库中的一些现有数据 并尝试使用相同的算法对其进行解密 我得到了值 但末尾有 16 个额外字节 这些字节都是垃圾 参见下面的代
  • 如何提取世界上每只海龟走过的路径并将其保存在 .csv 文件中?

    我仍在尝试提取世界上每只海龟所走路径的坐标 例如 我想知道海龟 0 所采取的路径是 patch 00 patch 0 5 patch 0 2 和 patch 1 4 并将此信息保存在 csv 文件中 这样 我想提取世界上所有海龟所走路径的坐
  • corr.test 与 cor.test p 值

    我正在尝试使用 psych 包 psych 1 6 9 中的 corr test 但在使用 method spearman 时 它似乎给出了与 cor test 不同的 p 值 相关系数相同 但 p 值不同 我整理了一些示例代码和输出 如下
  • 使用 roxygen2 记录数据集

    我正在尝试使用 roxygen2 记录 R 包中的一些数据集 仅考虑其中之一 I have mypkg data CpG human GRCh37 RDa 其中包含一个名为的对象CpG human GRCh37 和一个名为 mypkg R
  • numpy.genfromtxt 生成看起来像元组的数组,而不是二维数组 - 为什么?

    我在跑genfromtxt像下面这样 date conv lambda x str x replace time conv lambda x str x a np genfromtxt input txt delimiter skip he
  • 如何每次在新进程中打开文件而不考虑文件打开器

    我正在使用 windows 7 64 位 python 2 7 我正在打开文件 并监视文件更改 然后等待直到打开的文件关闭 这对于简单的记事本文件打开器来说效果很好 由于记事本在新的进程 ID 中打开每个文件 而记事本 在单个记事本 进程
  • Pylance 无法在 VSCode Jupyter 笔记本中工作

    皮兰斯工作于 py files 但不适用于 Jupyter ipynb笔记本 我尝试保存 ipynb 同样的问题 如何在我的笔记本中启用 Pylance 警告 Jupyter 扩展似乎不支持 Pylance 我提交这个问题就是为了解决这个缺
  • EntLib5:登录应用程序块未记录到事件日志(例外:无法构造 LogWriter 类型)-任何人都可以帮忙吗?

    你好呀 我刚刚设置了 Enterprise Library 5 的日志记录应用程序块部分 我认为我已经完成了正确的操作 但它没有记录到事件日志 它在写入方法上出错并给出了以下异常 The type LogWriter cannot be c