You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure App Service中ASP.NET Core日志功能失效问题求助

问题:ASP.NET Core 7.0 RC2部署Azure App Service后日志功能失效,启动报错

我将代码库部署在两个独立的Azure App Service实例上:

  • 使用ASP.NET Core Logging Integration 6.0.8的实例,日志功能正常
  • 使用7.0.0-rc-2-22476-2版本的实例,日志完全无法工作,服务启动时抛出以下错误:
2022-10-25T21:07:05 sandboxproc.exe D:\DWASFiles\Sites\teams1stdevelopment\Temp\applicationhost.config True True
2022-10-25T21:07:05 env XPROC_TYPENAME=Microsoft.Web.Hosting.Transformers.ApplicationHost.SiteExtensionHelper, Microsoft.Web.Hosting, Version=7.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
2022-10-25T21:07:05 env XPROC_METHODNAME=Transform
2022-10-25T21:07:05 Start 'Microsoft.AspNetCore.AzureAppServices.SiteExtension' site extension transform
2022-10-25T21:07:05 StartSection Executing InsertIfMissing (transform line 7, 23)
2022-10-25T21:07:05 on /configuration/system.webServer
2022-10-25T21:07:05 Applying to 'configuration' element (no source line info)
2022-10-25T21:07:05 EndSection Done executing InsertIfMissing
2022-10-25T21:07:05 StartSection Executing InsertIfMissing (transform line 8, 16)
2022-10-25T21:07:05 on /configuration/system.webServer/runtime
2022-10-25T21:07:05 Applying to 'system.webServer' element (no source line info)
2022-10-25T21:07:05 Inserted 'runtime' element
2022-10-25T21:07:05 EndSection Done executing InsertIfMissing
2022-10-25T21:07:05 StartSection Executing InsertIfMissing (transform line 9, 31)
2022-10-25T21:07:05 on /configuration/system.webServer/runtime/environmentVariables
2022-10-25T21:07:05 Applying to 'runtime' element (no source line info)
2022-10-25T21:07:05 EndSection Done executing InsertIfMissing
2022-10-25T21:07:05 :(10,406), Microsoft.Web.XmlTransform.XmlNodeException: Could not resolve 'InsertOrAppendAttribute' as a type of Transform ---> Microsoft.Web.XmlTransform.XmlTransformationException: Could not resolve 'InsertOrAppendAttribute' as a type of Transformat Microsoft.Web.XmlTransform.NamedTypeFactory.Construct[ObjectType](String typeName)at Microsoft.Web.XmlTransform.XmlElementContext.CreateObjectFromAttribute[ObjectType](String& argumentString, XmlAttribute& objectAttribute)--- End of inner exception stack trace ---at Microsoft.Web.XmlTransform.XmlElementContext.ConstructTransform(String& argumentString)at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement(XmlElementContext context)at Microsoft.Web.XmlTransform.XmlTransformation.TransformLoop(XmlNodeContext parentContext)
2022-10-25T21:07:05 :(11,158), Microsoft.Web.XmlTransform.XmlNodeException: Could not resolve 'InsertOrAppendAttribute' as a type of Transform ---> Microsoft.Web.XmlTransform.XmlTransformationException: Could not resolve 'InsertOrAppendAttribute' as a type of Transformat Microsoft.Web.XmlTransform.NamedTypeFactory.Construct[ObjectType](String typeName)at Microsoft.Web.XmlTransform.XmlElementContext.CreateObjectFromAttribute[ObjectType](String& argumentString, XmlAttribute& objectAttribute)--- End of inner exception stack trace ---at Microsoft.Web.XmlTransform.XmlElementContext.ConstructTransform(String& argumentString)at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement(XmlElementContext context)at Microsoft.Web.XmlTransform.XmlTransformation.TransformLoop(XmlNodeContext parentContext)
2022-10-25T21:07:05 :(12,146), Microsoft.Web.XmlTransform.XmlNodeException: Could not resolve 'InsertOrAppendAttribute' as a type of Transform ---> Microsoft.Web.XmlTransform.XmlTransformationException: Could not resolve 'InsertOrAppendAttribute' as a type of Transformat Microsoft.Web.XmlTransform.NamedTypeFactory.Construct[ObjectType](String typeName)at Microsoft.Web.XmlTransform.XmlElementContext.CreateObjectFromAttribute[ObjectType](String& argumentString, XmlAttribute& objectAttribute)--- End of inner exception stack trace ---at Microsoft.Web.XmlTransform.XmlElementContext.ConstructTransform(String& argumentString)at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement(XmlElementContext context)at Microsoft.Web.XmlTransform.XmlTransformation.TransformLoop(XmlNodeContext parentContext)
2022-10-25T21:07:05 Fail 'Microsoft.AspNetCore.AzureAppServices.SiteExtension' site extension transform
2022-10-25T21:07:05 sandboxproc.exe Elapsed = 426.00 ms failed with System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Fail transforming applicationHost.config with 'C:\home\SiteExtensions\Microsoft.AspNetCore.AzureAppServices.SiteExtension\applicationHost.xdt' with :(10,406), Microsoft.Web.XmlTransform.XmlNodeException: Could not resolve 'InsertOrAppendAttribute' as a type of Transform ---> Microsoft.Web.XmlTransform.XmlTransformationException: Could not resolve 'InsertOrAppendAttribute' as a type of Transformat Microsoft.Web.XmlTransform.NamedTypeFactory.Construct[ObjectType](String typeName)at Microsoft.Web.XmlTransform.XmlElementContext.CreateObjectFromAttribute[ObjectType](String& argumentString, XmlAttribute& objectAttribute)--- End of inner exception stack trace ---at Microsoft.Web.XmlTransform.XmlElementContext.ConstructTransform(String& argumentString)at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement(XmlElementContext context)at Microsoft.Web.XmlTransform.XmlTransformation.TransformLoop(XmlNodeContext parentContext):(11,158), Microsoft.Web.XmlTransform.XmlNodeException: Could not resolve 'InsertOrAppendAttribute' as a type of Transform ---> Microsoft.Web.XmlTransform.XmlTransformationException: Could not resolve 'InsertOrAppendAttribute' as a type of Transformat Microsoft.Web.XmlTransform.NamedTypeFactory.Construct[ObjectType](String typeName)at Microsoft.Web.XmlTransform.XmlElementContext.CreateObjectFromAttribute[ObjectType](String& argumentString, XmlAttribute& objectAttribute)--- End of inner exception stack trace ---at Microsoft.Web.XmlTransform.XmlElementContext.ConstructTransform(String& argumentString)at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement(XmlElementContext context)at Microsoft.Web.XmlTransform.XmlTransformation.TransformLoop(XmlNodeContext parentContext):(12,146), Microsoft.Web.XmlTransform.XmlNodeException: Could not resolve 'InsertOrAppendAttribute' as a type of Transform ---> Microsoft.Web.XmlTransform.XmlTransformationException: Could not resolve 'InsertOrAppendAttribute' as a type of Transformat Microsoft.Web.XmlTransform.NamedTypeFactory.Construct[ObjectType](String typeName)at Microsoft.Web.XmlTransform.XmlElementContext.CreateObjectFromAttribute[ObjectType](String& argumentString, XmlAttribute& objectAttribute)--- End of inner exception stack trace ---at Microsoft.Web.XmlTransform.XmlElementContext.ConstructTransform(String& argumentString)at Microsoft.Web.XmlTransform.XmlTransformation.HandleElement(XmlElementContext context)at Microsoft.Web.XmlTransform.XmlTransformation.TransformLoop(XmlNodeContext parentContext)at Microsoft.Web.Hosting.Transformers.ApplicationHost.SiteExtensionDefinition.Transform(XmlDocument document, IDictionary`2 environments, Boolean isMainSite, Boolean separateProcessForScm)at Microsoft.Web.Hosting.Transformers.ApplicationHost.SiteExtensionHelper.Transform(XmlDocument doc, List`1 definitions, IDictionary`2 environments, Boolean isMainSite, Boolean separateProcessForScm)at Microsoft.Web.Hosting.Transformers.ApplicationHost.SiteExtensionHelper.Transform(String appHostConfig, String isMainSiteStr, String separateProcessForScmStr)--- End of inner exception stack trace ---at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)at Microsoft.Web.Hosting.ProcessModel.Program.Main(String[] args)

已安装的NuGet包

已安装的NuGet包

Program.cs代码

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Identity;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;

namespace Microsoft.BotBuilderSamples
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration((context, config) =>
            {
                var keyVaultEndpoint = new Uri(Environment.GetEnvironmentVariable("VaultUri"));
                config.AddAzureKeyVault(keyVaultEndpoint, new DefaultAzureCredential());
            })
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.ConfigureLogging((logging) =>
                {
                    logging.AddDebug();
                    logging.AddConsole();
                });
                webBuilder.UseStartup<Startup>();
            });
    }
}

解决方案

这个错误根源是Azure App Service上的Microsoft.AspNetCore.AzureAppServices.SiteExtension扩展使用了环境不支持的InsertOrAppendAttribute XML转换类型,属于.NET 7 RC2预览版的兼容性问题,可按以下方案解决:

  1. 卸载问题站点扩展
    登录Azure门户,进入目标App Service的「扩展」页面,找到Microsoft.AspNetCore.AzureAppServices.SiteExtension并删除,随后重启App Service。

  2. 升级到.NET 7正式版
    RC2是预览版本,存在已知适配bug,建议直接将项目升级到.NET 7正式版,同步更新所有相关NuGet包(包括Microsoft.Extensions.Logging.AzureAppServices至7.0.0及以上正式版本)。

  3. 手动配置Azure日志
    如果暂时无法升级,可绕过站点扩展,手动配置日志:

    • 修改Program.cs,添加Azure App Services日志提供器:
      webBuilder.ConfigureLogging((context, logging) =>
      {
          logging.AddDebug();
          logging.AddConsole();
          // 添加Azure App Service日志支持
          logging.AddAzureWebAppDiagnostics();
          // 设置日志最低级别
          logging.SetMinimumLevel(LogLevel.Information);
      });
      
    • 在Azure门户的App Service「监测」-「日志流」中,启用应用日志和Web服务器日志,可选择存储到Azure存储账户或直接查看实时日志。
  4. 清理残留扩展文件
    通过Kudu控制台进入C:\home\SiteExtensions目录,删除残留的Microsoft.AspNetCore.AzureAppServices.SiteExtension文件夹,避免旧配置干扰。


内容的提问来源于stack exchange,提问作者Rich H.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 23:01:23