abp9 .net8 升级错误记录-错误八、

时间:2024-03-29 08:14:36
.net8中, 使用了新的Host.CreateDefaultBuilder(args)创建服务, 因此, 需要对:Program 和Startup 进行修改:

Program

 using Abp.AspNetCore.Dependency;  
using Abp.Dependency;  
using Microsoft.AspNetCore.Hosting;  
using Microsoft.Extensions.Hosting;  
namespace XXXX.XXX.Web.Startup  
{  
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        internal static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            })
            .UseCastleWindsor(IocManager.Instance.IocContainer);
    }
}

Startup
ConfigureServices方法的返回值修改为void最后一行的return xxx修改为:

// Configure Abp and Dependency Injection  services.AddAbpWithoutCreatingServiceProvider<SCMWebMvcModule>(options => 
      options.IocManager.IocContainer.AddFacility<LoggingFacility>(  
      f => f.UseAbpLog4Net().WithConfig(_env.IsDevelopment()  
      ? "log4net.config"  
      : "log4net.Production.config"  
      )  
));

需要新增log4net.Production.config

 <?xml version="1.0" encoding="utf-8"?>

<log4net>
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
        <file value="App_Data/Logs/Logs.log" />
        <appendToFile value="true" />
        <rollingStyle value="Size" />
        <maxSizeRollBackups value="10" />
        <maximumFileSize value="10000KB" />
        <staticLogFileName value="true" />
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date || %5level || %logger || %message || %exception ||end %newline" />
        </layout>
    </appender>
    <root>
        <appender-ref ref="RollingFileAppender" />
        <level value="DEBUG" />
    </root>
    <logger name="NHibernate">
        <level value="WARN" />
    </logger>
</log4net>