使用Microsoft.EnterpriseLibrary5.0时出错
本文关键字:出错 0时 EnterpriseLibrary5 Microsoft 使用 | 更新日期: 2023-09-27 18:10:45
我想使用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:
依赖项解析失败,类型=Microsoft.Practices.EnterpriseLibrary.Logging '"。LogWriter'", name ='"(无)'"。'r'在调用构造函数时发生异常Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener (System.String文件名,系统。字符串头,系统。字符串页脚,Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter格式化程序)。'r' excepeption is: IOException -设备不存在准备好了。' r ' n ' r ' n -----------------------------------------------' r ' nAt异常发生的时间,容器为:'r'n'r'n默认Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl LogWriter。(映射自microsoft . practices . enterpriselilibrary . logging . logwriter,(none))'r'n解析构造函数的参数"structureHolder"Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl (Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolderstructureHolder,Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProviderinstrumentationProvider,Microsoft.Practices.EnterpriseLibrary.Logging.ILoggingUpdateCoordinatorupdateCoordinator) ' r ' n解决默认Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder LogWriterStructureHolder。(映射Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder,(none) 'r'n解析构造函数的参数"traceSources'"Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder (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.IEnumerable
1[[System.]字符串,mscorlib,版本=4.0.0.0,文化=中性,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
1[[System.Diagnostics.TraceListener]系统,版本=4.0.0.0,文化=中性,都必须要]]tracelistener这种,System. diagnostics . sourcelevels level, System。布尔autoFlushMicrosoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProviderinstrumentationProvider) ' r ' n解决Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.ReconfigurableTraceListenerWrapper,平FileTrace监听器(从System.Diagnostics映射)。TraceListener这种,平FileTrace Listener)'r'n解析参数'" wrappedtracellistener '"的构造函数Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.ReconfigurableTraceListenerWrapper (System.Diagnostics.TraceListenerwrappedTraceListener,Microsoft.Practices.EnterpriseLibrary.Logging.ILoggingUpdateCoordinator协调员)' r ' n 解决Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener,平FileTrace Listener实现(映射自System.Diagnostics。tracellistener, Flat FileTrace监听器(implementation)'r'n调用构造函数Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener (System.String文件名,系统。字符串头,系统。字符串页脚,Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter格式化程序)
Resolving parameter '"traceListeners'" of constructor Microsoft.Practices.EnterpriseLibrary.Logging.LogSource(System.String name, System.Collections.Generic.IEnumerable
它有这个InnerException:
设备未准备好。
如何解决这个错误?
阅读以下文章:如何配置和使用microsoftenterprise Library 5进行日志记录
这个错误来自app.config文件。我会使用相同的app.config文件,有一些错误。当我使用app.config创建EntLib应用程序时,错误解决了。