企业库5.0日志到sql server无法正常工作

时间:2012-02-17 09:17:23

标签: enterprise-library sql-server-2008-express

我在使用Enterprise Library 5.0登录sql server 2008 Express时遇到问题 它适用于我的开发环境(VS2010),但不适用于我的Server 2008 / SQL Server 2008 Express。

为确保它不是数据库,我还使用平面文件进行了测试。也没用。

这两个文件都存在于我的bin目录中。

  

Microsoft.Practices.EnterpriseLibrary.Logging.dll   Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll

我的web.config看起来像这样:

<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" />
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
  <section name="Space4it.Registertime.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
  <add name="Database Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Database.Configuration.FormattedDatabaseTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging.Database, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    databaseInstanceName="TimeseddelLogging" writeLogStoredProcName="WriteLog"
    addCategoryStoredProcName="AddCategory" formatter="Text Formatter"
    traceOutputOptions="LogicalOperationStack, DateTime, Timestamp" />
</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="Database Trace Listener" />
    </listeners>
  </add>
</categorySources>
<specialSources>
  <allEvents switchValue="All" name="All Events">
    <listeners>
      <add name="Database Trace Listener" />
    </listeners>
  </allEvents>
  <notProcessed switchValue="All" name="Unprocessed Category" />
  <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
      <add name="Database Trace Listener" />
    </listeners>
  </errors>
</specialSources>
</loggingConfiguration>
<connectionStrings>
<add name="TimeseddelLogging" connectionString="Data Source=server\sqlexpress;Initial Catalog=logging.database;User ID=username;pwd=password"/>
</connectionStrings>

我使用此用户手动连接(作为测试),我可以使用此用户在日志表中输入数据。

我收到此错误: 例外:

消息:

  

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

堆栈:

  

位于Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstanceTService的Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(类型serviceType,String key),位于Space4it.Common.Log的Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer() SpaceLog上的.Log.DoLog(String message,String category,Dictionary`2 metaData,Exception ex,TraceEventType type,LogPriority priority,Int32 eventId)。Space4it.Registertime.Pages.TestForm.ButtonTest_Click(Object sender,EventArgs e)

内部例外: 消息:

  

依赖项的解析失败,type =“Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter”,name =“(none)”。在解决时发生异常:例外情况是:InvalidOperationException - 无法构造数据库类型。您必须配置容器以提供此值。 - - - - - - - - - - - - - - - - - - - - - - - - 当时例外,容器是:解析Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl,LogWriter。默认(从Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter映射,(无))解析参数“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)解决Microsoft .Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder,LogWriterStructureHolder。默认(从Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder映射,(无))解析构造函数Microsoft.Practices.EnterpriseLibra的参数“traceSources” ry.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) Resolving Microsoft.Practices.EnterpriseLibrary.Logging.LogSource,General 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 level,System.Boolean autoFlush,Microsoft.Practices。 EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider instrumentationProvider)解析Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.ReconfigurableTraceListenerWrapper,数据库跟踪侦听器(从System.Diagnostics.TraceListener映射,数据库跟踪侦听器)解析构造函数Microsoft.Practices.EnterpriseLibrary的参数“wrappedTraceListener” .Logging.TraceListeners.ReconfigurableTraceListenerWrapper(System.Diagnostics.TraceListener wrappedTraceListener,Microsoft.Practices.EnterpriseLibrary.Lo gging.ILoggingUpdateCoordinator coordinator)解析Microsoft.Practices.EnterpriseLibrary.Logging.Database.FormattedDatabaseTraceListener,数据库跟踪侦听实现(从System.Diagnostics.TraceListener映射,数据库跟踪侦听实现)解析构造函数Microsoft.Practices.EnterpriseLibrary.Logging.Database的参数“database” .FormattedDatabaseTraceListener(Microsoft.Practices.EnterpriseLibrary.Data.Database数据库,System.String writeLogStoredProcName,System.String addCategoryStoredProcName,Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter formatter)解析Microsoft.Practices.EnterpriseLibrary.Data.Database,TimeseddelLogging < / p>

内部异常堆栈:

  

at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType,String key)中的Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t,Object existing,String name,IEnumerable 1 resolverOverrides) at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable 1 resolverOverrides)< / p>

希望有人可以帮助我: - )

度过美好的一天!

1 个答案:

答案 0 :(得分:1)

您收到的错误表明Entlib尚未正确初始化。数据库是一个红色的鲱鱼 - 你现在还没有完成日志工作。

&lt; configSections&gt;中是否定义了日志记录部分?你的web.config文件的元素?

更新

您添加了configSections元素,但您发布的内容格式不正确:&lt; configSections&gt;&lt; / sectionGroup&gt;。如果这是准确的,那就是问题,配置错误。修复关闭标记,它应该开始工作。