title: Using TrackDependency is the right way to get metrics of a business logic layer .NET Library Class?
body: <p>I applied Application Insights in an MVC .NET project. The solution has 3 projects: the MVC project for the front-end, and 2 .NET Library Class projects, one for the business layer, and the other for the data access layer.</p>
  
  <p>By default, Application Insights automatically track HTTP requests and the SQL call, and the business logic layer is skipped.</p>
  
  <p>I tried to use TrackDependency to get metrics from the intermediate Library Class that have all the business logic of the application, and it seems to work.</p>
  
  <p>What I did was implement the following code in the Controller, just when it consumes the business layer method:</p>
  
  <pre><code>        LogicLayer.LogicLayer logObj = new LogicLayer.LogicLayer();
  
          TelemetryClient telemetry = new TelemetryClient();
  
          string stResponse = "";
          var success = false;
          var startTime = DateTime.UtcNow;
          var timer = System.Diagnostics.Stopwatch.StartNew();
          try
          {
              stResponse = logObj.getData();
              success = true;
          }
          catch (Exception ex)
          {
              success = false;
              telemetry.TrackException(ex);
              throw new Exception("Operation went wrong", ex);
          }
          finally
          {
              timer.Stop();
              telemetry.TrackDependency("DependencyType", "myDependency", "myCall", "", startTime, timer.Elapsed, "", success);
          }
  </code></pre>
  
  <p>My question is: Using TrackDependency is the right way to get metrics on the intermediate Library Class that have all the business logic of the application ??? or is there another way ??</p>