visual-studio-2013 - 更改企业库日志记录中的源名称

标签 visual-studio-2013 enterprise-library

我正在使用企业库日志记录来轻松登录到 Windows 中的事件查看器。

但我不知道如果可能的话如何在企业库中更改源记录到我的应用程序的名称(例如 MyApp)。

Event Viewer

我正在使用可视化编辑器轻松编辑企业库日志记录中的选项,称为:企业库配置,如图所示。

Enterprise Library Configuration

这是我的 App.config 文件,由企业库配​​置编辑器生成:

<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    <section name="SettingsConfiguration" type="ET.Settings.SettingsConfigurationSection, E-Trace.Settings, Version=1.0.0.0, Culture=neutral, PublicKeyToken=403b794e0e68acbe" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="Event Log" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        source="Enterprise Library Logging" formatter="Simple Formatter"
        log="Application" traceOutputOptions="Timestamp, Callstack"
        filter="All" asynchronous="true" />
      <add listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        type="ET.Logging.TraceListener.ConsoleTraceListener, E-Trace.Logging, Version=1.1.0.0, Culture=neutral, PublicKeyToken=403b794e0e68acbe"
        name="ConsoleTraceListener" formatter="Simple Formatter" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        template="{timestamp(local)} -  {severity}  : {message}" name="Simple Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="ConsoleTraceListener" />
          <add name="Event Log" />
        </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="ConsoleTraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="Log Only Policy">
        <exceptionTypes>
          <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="None">
            <exceptionHandlers>
              <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                logCategory="General" eventId="100" severity="Error" title="Services"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                priority="0" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
      <add name="Log And Notify">
        <exceptionTypes>
          <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="None">
            <exceptionHandlers>
              <add name="Logging Exception Handler" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                logCategory="General" eventId="100" severity="Error" title="Services"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling"
                priority="0" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>
</configuration>

最佳答案

答案是您需要以管理员身份运行控制台一次,以便它可以创建源。

我正在使用this Visual Studio 2013 插件,用于轻松编辑配置。

关于visual-studio-2013 - 更改企业库日志记录中的源名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27016589/

相关文章:

logging - 企业库 5 日志记录 block : How to write to event viewer?

html - 如何使用 Microsoft Enterprise Library 发送 HTML 格式的电子邮件?

.net - 使用备份 appender 进行日志记录

logging - Enterprise Library Logging Distributor 配置中的 TraceListenerData 类型无效

jquery - 突然的 JavaScript 错误

visual-studio-2013 - 无法安装 WebEssentials - "extension not installable on ... installed products"

c++ - 在调试器上的 CStringArray 中显示元素一再一?

c# - 使用企业库异常 block 的 WCF 异常屏蔽

c++ - 如何使用AfxMessageBox打印符号 "↑"?

visual-studio-2013 - 是否可以自动执行使用 Visual Studio 2013 测试工具创建的负载测试?