使用Microsoft.EnterpriseLibrary5.0时出错

时间:2013-04-24 13:16:57

标签: c# enterprise-library-5

我想使用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 =   \“(无)\”。\ r \ n发生异常时:调用构造函数   Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener(System.String   fileName,System.String标题,System.String页脚,   Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter   formatter)。\ r \ n \ nException是:IOException - 设备不是   准备好了。\ r \ n \ r \ n ---------------------------------------- ------- \ r \ NAT   例外的时间,容器是:\ r \ n \ r \ n解析   Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl,日志写。默认   (从Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter映射,   (无))\ r \ n解析构造函数的参数\“structureHolder \”   Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder   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解析构造函数的参数\“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.String,mscorlib,   Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089]]   traceSourceNames,   System.Collections.Generic.IEnumerable 1[[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,   系统,版本= 4.0.0.0,文化=中立,   PublicKeyToken = b77a5c561934e089]] traceListeners,   System.Diagnostics.SourceLevels级别,System.Boolean autoFlush,   Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider   instrumentationProvider)\ r \ n解析   Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.ReconfigurableTraceListenerWrapper,平   FileTrace Listener(从System.Diagnostics.TraceListener映射,Flat   FileTrace Listener)\ r \ n解析参数   构造函数的“wrappedTraceListener”   Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.ReconfigurableTraceListenerWrapper(System.Diagnostics.TraceListener   wrappedTraceListener,   Microsoft.Practices.EnterpriseLibrary.Logging.ILoggingUpdateCoordinator   协调员)\ r \ n解决   Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener,平   FileTrace Listenerimplementation(映射自   System.Diagnostics.TraceListener,Flat FileTrace   Listenerimplementation)\ r \ n调用构造函数   Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener(System.String   fileName,System.String标题,System.String页脚,   Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter   格式化器)

它有这个InnerException:

  

设备尚未就绪。

如何解决此错误?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

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