0

我想使用 EnterpriseLibrary 5.0 dll 登录我的项目。为此,我已将这些 dll 添加到我的参考资料中:

Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.EnterpriseLibrary.Data
Microsoft.Practices.EnterpriseLibrary.Logging
Microsoft.Practices.EnterpriseLibrary.Logging.Database

然后我写这个:

using Microsoft.Practices.EnterpriseLibrary.Data; 
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration; 
using Microsoft.Practices.EnterpriseLibrary.Logging;

然后我写道:

LogEntry logEntry = new LogEntry();
logEntry.Message = "Message";
Logger.Write(logEntry);

但是当我的代码执行时,我在最后一行得到了这个异常:

尝试获取 LogWriter 类型的实例时发生激活错误,键“”

有这个 InnerException:

依赖项解析失败,type = \"Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter\", name = \"(none)\"。\r\n发生异常时:调用构造函数 Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners .FlatFileTraceListener(System.String fileName, System.String header, System.String footer, Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter 格式化程序)。\r\n异常是: IOException - 设备未准备好。\r\n \r\n---------------------------------------------- -\r\n发生异常时,容器为:\r\n\r\n 正在解决 Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl,LogWriter。默认 (映射自 Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(无))\r\n 解析构造函数 Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder structureHolder) 的参数“structureHolder” , Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider instrumentationProvider, Microsoft.Practices.EnterpriseLibrary.Logging.ILoggingUpdateCoordinator updateCoordinator)\r\n 正在解决 Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder,LogWriterStructureHolder。默认 (从 Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder 映射,(无))\r\n 解析构造函数 Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder 的参数 \"traceSources\"(System.Collections.Generic.IEnumerable 1[[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] filters, System.Collections.Generic.IEnumerable1[[ System.String,mscorlib,版本=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089]] traceSourceNames,System.Collections.Generic.IEnumerable1[[Microsoft.Practices.EnterpriseLibrary.Logging.LogSource, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]] traceSources, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource allEventsTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource notProcessedTraceSource, Microsoft.Practices.EnterpriseLibrary.Logging.LogSource errorsTraceSource, System.String defaultCategory, System.Boolean tracingEnabled, System.Boolean logWarningsWhenNoCategoriesMatch, System.Boolean revertImpersonation)\r\n Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogSource,Trace\r\n
Resolving parameter \"traceListeners\" of constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogSource(System.String name, System.Collections.Generic.IEnumerable
1[[System.Diagnostics.TraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] traceListeners, System.Diagnostics.SourceLevels 级别, System.Boolean autoFlush, Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation。 ILoggingInstrumentationProvider instrumentationProvider)\r\n 正在解析 Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.ReconfigurableTraceListenerWrapper、Flat FileTrace 侦听器(映射自 System.Diagnostics.TraceListener、Flat FileTrace 侦听器)\r\n 解析构造函数 Microsoft 的参数“wrappedTraceListener” .Practices.EnterpriseLibrary.Logging.TraceListeners.ReconfigurableTraceListenerWrapper(System.Diagnostics.TraceListener WrappedTraceListener,Microsoft.Practices.EnterpriseLibrary.Logging。ILoggingUpdateCoordinator 协调器)\r\n 正在解决 Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener、Flat FileTrace 侦听器‌实现(映射自 System.Diagnostics.TraceListener、Flat FileTrace 侦听器‌实现)\r\n 调用构造函数 Microsoft.Practices.EnterpriseLibrary.Logging。 TraceListeners.FlatFileTraceListener(System.String 文件名,System.String 标头,System.String 页脚,Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter 格式化程序)EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener(System.String 文件名,System.String 标头,System.String 页脚,Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter 格式化程序)EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener(System.String 文件名,System.String 标头,System.String 页脚,Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter 格式化程序)

它有这个 InnerException:

设备未准备好。

我该如何解决这个错误?

4

2 回答 2

1

阅读以下文章:如何配置和使用 Microsoft Enterprise Library 5 进行日志记录

于 2013-04-24T13:27:07.393 回答
1

此错误来自 app.config 文件。我会使用有一些错误的相同 app.config 文件。当我使用使用 EntLib 应用程序创建的 app.config 时,我的错误解决了。

于 2013-05-18T08:18:01.567 回答