Search code examples
azureloggingrequestazure-service-fabric

How to see request logs Service Fabric Application


I want to know if is there a way to see all the requests made to my service fabric application while it is already published on azure servers, or at least capture all requests and save them in some place, I need informations like source and body.

Thanks in advance!


Solution

  • To see all the requests and responses, you first need to log them in somewhere. Here are the available approaches:

    • Streaming into VS Cloud Explorer

    You could use ServiceEventSource to log the valuable information and then you will be able to see it by attaching to your SF cluster via CloudExplorer in VS. Here is you could find more info - Debug your Service Fabric application by using Visual Studio.

    • Windows Azure Diagnostics

    WAD extension that you could install on your VM-s uploads logs to Azure Storage, and also has the option to send logs to Azure Application Insights or Event Hubs. Check out Event aggregation and collection using Windows Azure Diagnostics.

    • EventFlow

    Using EventFlow allows you to have services send their logs directly to an analysis and visualization platform, and/or to storage. Other libraries (ILogger, Serilog, etc.) might be used for the same purpose, but EventFlow has the benefit of having been designed specifically for in-process log collection and to support Service Fabric services.

    • Event analysis and visualization with OMS

    When OMS is configured, you will have access to a specific OMS workspace, from where data can be queried or visualized in dashboards. After data is received by Log Analytics, OMS has several Management Solutions that are prepackaged solutions to monitor incoming data, customized to several scenarios. These include a Service Fabric Analytics solution and a Containers solution, which are the two most relevant ones to diagnostics and monitoring when using Service Fabric clusters. Find more info on Event analysis and visualization with OMS and Assess Service Fabric applications and micro-services with the Azure portal.

    And there is a number of ways how you could capture source and body, or whatever you need. Below you could find some:

    1. Apply ActionFilterAttribute on your controller class if you don't have one, and log all the information you need within OnActionExecuted method

    2. Add the middleware in Startup class -

      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);
      }