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

Visual studio 2013 更改企业库日志记录中的源名称,visual-studio-2013,enterprise-library,Visual Studio 2013,Enterprise Library,我正在使用企业库日志轻松地登录到windows中的事件查看器 但是我不知道如果可能,如何在企业库日志中将源代码更改为我的应用程序的名称(例如MyApp) 我正在使用可视化编辑器轻松编辑企业库日志记录中的选项,如图所示,该选项名为:企业库配置 这是由企业库配置编辑器生成的my App.config文件: <configuration> <configSections> <section name="loggingConfiguration" type=

我正在使用企业库日志轻松地登录到windows中的事件查看器

但是我不知道如果可能,如何在企业库日志中将源代码更改为我的应用程序的名称(例如MyApp)

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

这是由企业库配置编辑器生成的my 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>

问题是,您需要以管理员身份运行控制台一次,以便它可以创建源代码


我正在使用visual studio 2013插件以一种简单的方式编辑配置。

如果您希望以编程方式(而不是在app.config中)执行此操作,则需要在EventLog对象的属性中进行更改,如下所示:

// Trace Listeners
var eventLog = new EventLog("Application",
    ".",
    "MyApp Event Logging");
var eventLogTraceListener = new FormattedEventLogTraceListener(eventLog);

然后按照其他方式构建其余的日志配置

更改配置:
source=“Enterprise Library Logging”
source=“MyApp”
。您必须确保已创建事件日志项(例如,提前创建注册表项或使用提升的权限记录一条消息)。