2011-03-04 68 views
2

这里是我的配置文件为什么它从格式化不是下面的模板

<?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" /> 
     <add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       fileName="F:\MyLogFile.log" footer="" header="" rollInterval="Hour" 
       traceOutputOptions="None" formatter="Text Formatter" /> 
    </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} {severity} {message} " 
       name="Text Formatter" /> 
    </formatters> 
    <categorySources> 
     <add switchValue="All" name="General"> 
     <listeners> 
      <add name="Rolling Flat File Trace 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="Rolling Flat File Trace Listener" /> 
     </listeners> 
     </errors> 
    </specialSources> 
    </loggingConfiguration> 
</configuration> 

,当我使用我得到在日志文件中按以下

Logger.Write("hello world", "", 0, 0, TraceEventType.Information); 

代码

3/4/2011 7:40:26 PM错误类别''没有明确的映射。日志条目:
时间戳:2011/3/4下午七时40分26秒
消息:你好世界
类别:
优先级:0
事件ID:0
严重性:信息
标题:
机:MYPC
应用程序域:ConsoleApplication1.vshost.exe
的ProcessID:8912
进程名称:C:\ ConsoleApplication \ BIN \调试\ ConsoleApplication.vshost.exe
主题名称:
的Win32的ThreadId:5496
扩展属性:

我是什么做错了,使人们不尊重模板=“{时间戳} {严重} {消息}”我在定义格式化。

+0

你使用什么记录器?并显示所有配置文件 – Serghei 2011-03-04 19:48:19

+0

Enterpriese库日志块。你在配置文件中看到了什么? – 2011-03-04 20:00:04

回答

2

您已经使用名称“常规”定义了您的类别,但是在您登录时您使用的是类别“”。

Logger.Write("hello world", "", 0, 0, TraceEventType.Information); 

所以你的LogEntry没有被你的“常规”类别,而是由specialSourcenotProcessed处理。这就是信息“没有明确的类别映射”正试图告诉你。

要使用类别中的Write方法传递名称:

Logger.Write("hello world", "General", 0, 0, TraceEventType.Information); 

或因为“大将军”被定义为defaultCategory不指定类别。

+0

谢谢,不过现在我得到了“尝试获取LogWriter类型的实例时出现激活错误,键”“”错误。不确定这是否可以通过在dll中配置企业库日志记录块来实现。尽管我已经发布了一个单独的问题。 – 2011-03-07 14:28:40

相关问题