Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 将应用程序从企业库5升级到6_.net_Enterprise Library_Enterprise Library 6 - Fatal编程技术网

.net 将应用程序从企业库5升级到6

.net 将应用程序从企业库5升级到6,.net,enterprise-library,enterprise-library-6,.net,Enterprise Library,Enterprise Library 6,我正在将现有应用程序从5升级到6。我的应用程序是一个.NETWeb应用程序。我依靠企业库将任何错误记录到数据库(sql server) 我的应用程序还使用自定义数据库侦听器和自定义日志异常处理程序(在我的解决方案中都以单独的.net项目的形式) 因此,我已经安装了6个,并在应用程序启动时添加了以下代码- IConfigurationSource config = ConfigurationSourceFactory.Create(); Exception

我正在将现有应用程序从5升级到6。我的应用程序是一个.NETWeb应用程序。我依靠企业库将任何错误记录到数据库(sql server)

我的应用程序还使用自定义数据库侦听器和自定义日志异常处理程序(在我的解决方案中都以单独的.net项目的形式)

因此,我已经安装了6个,并在应用程序启动时添加了以下代码-

             IConfigurationSource config = ConfigurationSourceFactory.Create();
        ExceptionPolicyFactory factory = new ExceptionPolicyFactory(config);
        Logger.SetLogWriter(new LogWriterFactory().Create());

        ExceptionManager exceptionManager = factory.CreateManager();
当System.NotImplementedException点击Logger.SetLogWriter(新LogWriterFactory().Create())时,我得到一个System.NotImplementedException;代码行

编辑:更具体的错误详细信息

 System.NotImplementedException was unhandled by user code
 HResult=-2147467263
 Message=Must be implemented by subclasses.
 Source=Microsoft.Practices.EnterpriseLibrary.Logging
我做错了什么

这是我的web.config-

   <configSections>
<section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" requirePermission="true" />
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />


 </configSections>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
<listeners>
  <add name="Database Trace Listener" type="ExtendedPropertyDatabaseListener.ExtendedFormattedDatabaseTraceListener, ExtendedPropertyDatabaseListener" listenerDataType="ExtendedPropertyDatabaseListener.ExtendedFormattedDatabaseTraceListenerData, ExtendedPropertyDatabaseListener" databaseInstanceName="ablmprod" writeLogStoredProcName="Logging.WriteLog" addCategoryStoredProcName="Logging.AddCategory" formatter="Text Formatter" />
  <add name="Event Log Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" source="Enterprise Library Logging" formatter="Text Formatter" />
</listeners>
<formatters>
  <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.505.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" />
  <notProcessed switchValue="All" name="Unprocessed Category" />
  <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
      <add name="Event Log Trace Listener" />
    </listeners>
  </errors>
</specialSources>
</loggingConfiguration>
<exceptionHandling>
  <exceptionPolicies>
  <add name="Policy">
    <exceptionTypes>
      <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" postHandlingAction="NotifyRethrow">
        <exceptionHandlers>
          <add name="Logging Exception Handler" type="CustomExceptionLoggingHandler.CustomExceptionLoggingHandler, CustomExceptionLoggingHandler" logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling" formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" priority="0" />
        </exceptionHandlers>
      </add>
    </exceptionTypes>
  </add>
</exceptionPolicies>
</exceptionHandling>

编辑: 感谢@lrb让我走上了正确的道路。下面是有效的代码-

protected void Application_Start()
{
    LoggingConfiguration loggingConfiguration = BuildLoggingConfig();
    LogWriter logWriter = new LogWriter(loggingConfiguration);
    Logger.SetLogWriter(logWriter, false);
    ExceptionPolicy.SetExceptionManager(exManager);

    // Create the default ExceptionManager object programatically
    exManager = BuildExceptionManagerConfig(logWriter);

    // Create an ExceptionPolicy to illustrate the static HandleException method
    ExceptionPolicy.SetExceptionManager(exManager);

           ...
}

private static LoggingConfiguration BuildLoggingConfig()
{
    // Formatters

    var config = new LoggingConfiguration();

    return config;
}

private static ExceptionManager BuildExceptionManagerConfig(LogWriter logWriter)
{
    var policies = new List<ExceptionPolicyDefinition>();

    var logAndWrap = new List<ExceptionPolicyEntry>
            {

                new ExceptionPolicyEntry(typeof (Exception),
                    PostHandlingAction.ThrowNewException,
                    new IExceptionHandler[]
                     {
                       new WrapHandler("An application error has occurred.",
                         typeof(APIAvailabilityException))
                     })
            };

    policies.Add(new ExceptionPolicyDefinition("Policy", logAndWrap));

    return new ExceptionManager(policies);
}
受保护的无效应用程序\u Start()
{
LoggingConfiguration LoggingConfiguration=BuildLoggingConfig();
LogWriter LogWriter=新的LogWriter(loggingConfiguration);
Logger.SetLogWriter(logWriter,false);
ExceptionPolicy.SetExceptionManager(exManager);
//以编程方式创建默认ExceptionManager对象
exManager=BuildExceptionManagerConfig(日志编写器);
//创建一个ExceptionPolicy来说明静态HandleException方法
ExceptionPolicy.SetExceptionManager(exManager);
...
}
私有静态日志配置BuildLoggingConfig()
{
//格式化程序
var config=new LoggingConfiguration();
返回配置;
}
专用静态异常管理器BuildExceptionManagerConfig(LogWriter LogWriter)
{
var policies=新列表();
var logAndWrap=新列表
{
新例外政策条目(类型)(例外),
PostHandlingAction.ThrowNewException,
新的IEExceptionHandler[]
{
new WrapHandler(“发生了应用程序错误。”,
类型(APIAvailabilityException))
})
};
添加(新的例外政策定义(“政策”,logAndWrap));
返回新的例外管理器(策略);
}

它有一点变化。您只需要一个虚拟的ConfugurationSource。这默认为一切,因为它是为我工作。请注意
SetLogWriter
方法的可选
ThrowIfSet
参数。文件规定:

throwIfSet:如果已设置写入程序,则为true将引发异常;否则就错了。默认为true


它有点变了。您只需要一个虚拟的ConfugurationSource。这默认为一切,因为它是为我工作。请注意
SetLogWriter
方法的可选
ThrowIfSet
参数。文件规定:

throwIfSet:如果已设置写入程序,则为true将引发异常;否则就错了。默认为true


对于仍然存在此问题且建议的解决方案不起作用的人,请提供更多信息

此异常的一个可能原因是
CoreBuildTraceListener
方法未在自定义
tracelistenerda
类中实现(如果使用)

在我的例子中,我必须添加以下内容才能使其正常工作(代码是针对我的实现的):


对于仍然存在此问题且建议的解决方案不起作用的人,请提供更多信息

此异常的一个可能原因是
CoreBuildTraceListener
方法未在自定义
tracelistenerda
类中实现(如果使用)

在我的例子中,我必须添加以下内容才能使其正常工作(代码是针对我的实现的):

IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
LogWriterFactory logWriterFactory = new LogWriterFactory(configurationSource);                
Logger.SetLogWriter(logWriterFactory.Create(),false);
Logger.Write(le);
protected override TraceListener CoreBuildTraceListener(LoggingSettings settings)
{
    return new RollingXmlTraceListener(
        this.FileName,
        this.RollSizeKB,
        this.TimeStampPattern,
        this.RollFileExistsBehavior,
        this.RollInterval,
        this.MaxArchivedFiles);
}