c# - Enterprise Library 4.1 Logger,日志在哪里?

标签 c# logging enterprise-library

我已经使用配置向导完成了它的配置,但我不明白它在哪里记录消息。我什至看到了 app.config 文件,但找不到任何日志记录源。

请指导我在哪里记录日志以及如何检查该日志。

这是我的配置文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add fileName="C:\Users\Administrator\Desktop\EAMS\trace.log"
        header="----------------------------------------" footer="----------------------------------------"
        formatter="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="LogicalOperationStack" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="FlatFile TraceListener" />
      <add source="Enterprise Library Logging" formatter="Text Formatter"
        log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="LogicalOperationStack" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Formatted EventLog TraceListener" />
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </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="Formatted EventLog TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <connectionStrings>
    <add name="ConnectionString" connectionString="Data Source=YAWARLAPTOP;Initial Catalog=EAMS;Integrated Security=true"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

最佳答案

您需要配置一个或多个Trace Listeners .另见 Configuration Overview

编辑 1 感谢您提供配置文件的示例。您正在将消息记录到应用程序事件日志中。请打开这个Event Log和往常一样,您将能够在其中看到您的消息。

编辑 2 在您最初的问题中,您询问了消息的记录位置。这个答案已经提供给你了。当你写一个问题时,最好提前说明你想要达到什么目的。要登录平面文件,在配置平面文件监听器后,您需要将对此监听器的引用添加到源中。查看示例中的事件日志跟踪监听器是如何完成的,并遵循相同的模式。

关于c# - Enterprise Library 4.1 Logger,日志在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5896576/

相关文章:

c# - 如何在 C# 中编写 sbit

c# - 企业库异常: Activation error occured while trying to get instance of type ICacheManager, key ?

c# - entlib 无效的 TraceListenerData 类型

c# - 与 Microsoft Enterprise Library 共享 MySQL 连接

c# - 如何在 C# 中获取模数?

c# - 不能在用户事务内使用 CREATE FULLTEXT INDEX/CATALOG 语句

C#统一:use of dynamic for a message/event system

Java,通过反射记录方法名称

python - 我怎样才能得到所有可能的日志级别的数组?

java - 跨线程保留 Java 堆栈跟踪