【问题标题】:How to see request logs Service Fabric Application如何查看请求日志 Service Fabric 应用程序
【发布时间】:2017-07-31 20:34:42
【问题描述】:

我想知道是否有办法查看对我的服务结构应用程序发出的所有请求,而它已经发布在 azure 服务器上,或者至少捕获所有请求并将它们保存在某个地方,我需要诸如源之类的信息和身体。

提前致谢!

【问题讨论】:

  • 您创建什么样的服务?是 ASP.NET Core 服务吗?还是 Web-Api?
  • @KirylZ 这是一个无状态的 ASP.NET Core Web-API。
  • 您可以使用 Application Insights 集成,请参阅stackoverflow.com/questions/45386898/…

标签: azure logging request azure-service-fabric


【解决方案1】:

要查看所有请求和响应,您首先需要将它们登录到某个位置。以下是可用的方法:

  • 流式传输到 VS Cloud Explorer

您可以使用 ServiceEventSource 记录有价值的信息并 然后您将能够通过附加到您的 SF 集群来查看它 VS 中的 CloudExplorer。您可以在这里找到更多信息 - Debug your Service Fabric application by using Visual Studio

  • Windows Azure 诊断

您可以在 VM-s 上安装的 WAD 扩展将日志上传到 Azure 存储,并且还可以选择将日志发送到 Azure Application Insights 或事件中心。查看Event aggregation and collection using Windows Azure Diagnostics

  • 事件流

使用EventFlow 可以让服务将其日志直接发送到分析和可视化平台和/或存储。其他库(ILogger、Serilog 等)可能用于相同目的,但 EventFlow 的优势在于专为进程内日志收集和支持 Service Fabric 服务而设计。

  • 使用 OMS 进行事件分析和可视化

配置 OMS 后,您将有权访问特定的 OMS 工作区,从中可以在仪表板中查询或可视化数据。 Log Analytics 接收到数据后,OMS 有几个管理解决方案,它们是用于监控传入数据的预打包解决方案,针对多个场景进行定制。其中包括 Service Fabric 分析解决方案和容器解决方案,这是使用 Service Fabric 群集时与诊断和监视最相关的两个解决方案。在Event analysis and visualization with OMSAssess Service Fabric applications and micro-services with the Azure portal 上查找更多信息。

您可以通过多种方式捕获源和主体,或者您需要的任何内容。您可以在下面找到一些:

  1. 如果不这样做,请在控制器类上应用 ActionFilterAttribute 有一个,并在 OnActionExecuted 方法中记录您需要的所有信息

  2. 在 Startup 类中添加中间件 -

    public static void ConfigureApp(IAppBuilder appBuilder)
    {
        // Configure Web API for self-host. 
        HttpConfiguration config = new HttpConfiguration();
    
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    
    
        appBuilder.Use(async (IOwinContext context, Func<Task> next) =>
        {
            await next.Invoke();
            // log anything you want here
            ServiceEventSource.Current.Message($"Response status code = {context.Response.StatusCode}");
        });
    
        appBuilder.UseWebApi(config);
    }
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-07
    • 2020-09-30
    • 2011-12-15
    • 1970-01-01
    • 2022-06-15
    • 2017-05-20
    • 1970-01-01
    • 2016-06-13
    相关资源
    最近更新 更多