【问题标题】:How to see the dependency issues at appstart on the Azure WebApps .net core如何在 Azure WebApps .net 核心上的 appstart 中查看依赖问题
【发布时间】:2017-11-13 00:36:06
【问题描述】:

当我们部署缺少依赖项的应用程序时,我们会收到 500 个错误,但不是很有帮助。由于应用程序无法启动,我们无法使用 appinsight 捕获错误。 我们怎样才能有更好的错误?

将构建任务添加为索引源和发布符号会有帮助吗?

关于应用 - .net 核心 - 未预先编译视图。

使用 nlog 启用的 Azure 详细错误和 appinsights。

通用错误就像

http://www.w3.org/1999/xhtml”> IIS详解 错误 - 500.0 - 内部服务器错误

【问题讨论】:

标签: asp.net-mvc azure asp.net-web-api asp.net-core


【解决方案1】:

我建议安装 Application Insights。然后,您可以在客户端和服务器端获得有关异常和应用程序性能的非常详细的消息。集成它非常简单,可以通过 Visual Studio 完成。

【讨论】:

  • 500 错误未显示,因为我们认为应用启动时出现错误
【解决方案2】:

两步解决问题

第 1 步。 var host = new WebHostBuilder().CaptureStartupErrors(true)

第 2 步。创建日志文件夹

第 3 步。添加一个类来获取反射错误。

第 4 步。转到 kudu 并在 web.config 中启用日志记录

第 5 步。找到错误并查看相关依赖。

第 6 步。写一个 nuget,因为 .core 喜欢 nuget,但讨厌直接依赖。

 public class ReflectionTypeLoadExceptionLoggingMiddleware
    {
        private readonly RequestDelegate _next;
        private readonly Microsoft.Extensions.Logging.ILogger _logger;
        public ReflectionTypeLoadExceptionLoggingMiddleware(RequestDelegate next, ILoggerFactory loggerFactory)
        {
            _next = next;
            _logger = loggerFactory.CreateLogger<ReflectionTypeLoadExceptionLoggingMiddleware>();
        }
        public async Task Invoke(HttpContext httpContext)
        {
            try
            {
                await _next(httpContext);
            }
            catch (Exception ex)
            {
                var reflectionTypeLoadException = ex as ReflectionTypeLoadException;
                if (reflectionTypeLoadException != null && reflectionTypeLoadException.LoaderExceptions != null)
                {
                    _logger.LogError("ReflectionTypeLoadException {0}", ex);
                    _logger.LogError("Loader exceptions messages: ");
                    foreach (var exception in reflectionTypeLoadException.LoaderExceptions)
                    {
                        _logger.LogError("ex {0}", exception);
                    }
                }
                throw;
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 2020-04-04
    • 2021-05-12
    相关资源
    最近更新 更多