Skip to end of metadata
Go to start of metadata

One of the purpose of logging is monitoring your application for critical aspects of your application, such as performance, errors, user behaviors and much more. Azure Application Insights provides a repository that holds these kind of logs and presents them in Azure Application Insights reporting tools, enabling you to easily monitor your application in real time.

This page gives you an overview of Azure Application Insights Logging and how to enable Crosslight Logging Framework to work with Azure Application Insights.

To learn more about the Crosslight logging concept in general, see Implementing Application Logging.

On this page:


Azure Application Insights provides an online repository where you can store your application logs and monitor it directly. To use this service, you will need an active Microsoft Azure subscription. In the Azure portal, you must create a new Application Insights Source for your application, please refer to the following links for details.

After you have created the Application Insights Source, you will get the instrumentation key to be used in your application.

Enabling Azure Insights Application Logging

To enable Azure Insights Application Logging in your application, you need to do the following steps.

Configuring Core Project

To enable Azure Insight application logging, first you need to configure your projects to add the Crosslight Logging Extensions, namely Intersoft.Crosslight.Logging.AzureInsights and Intersoft.Crosslight.Logging.AzureInsights.Server. In the core project, you must add reference to Intersoft.Crosslight.Logging.AzureInsights as follows.

Configuring Web Api Project

Next, you need to configure your WebAPI project, please add reference to Intersoft.Crosslight.Logging.AzureInsights.Server as follows.

Afterward, you will also need to add Application Insights for WebApplications package from Nuget. 

Lastly, you need to create a WebApiController that accepts the Azure Insights Telemetries from your application as follows.

Registering IAzureInsightsService

After your projects are configured, you can then register the IAzureInsightService in your AppService class as follows.

It's recommended that you create one Azure Insights for each platform. In such case, you can check the running platform at runtime and set the service's InstrumentionKey accordingly. To check the running platform, you can resolve an IApplicationService instance from the service provider, and call the IApplicationService.GetContext().Platform API.

Using AzureInsightEventSource to Track Telemetries

You can track custom telemetries by using AzureInsightsEventSource such as follows.

Using AzureInsightsApplicationEventSource to Track Application Events

In addition to using AzureInsightsEventSource, you can also use AzureInsightsApplicationEventSource to track Crosslight application-specific events such as follows:

  • Activated
  • Deactivated
  • DeviceTokenReceived
  • Navigated
  • NotificationReceived
  • Paused
  • Resumed
  • Started
  • SyncCancelled
  • Synced
  • Terminated

By default, Crosslight Azure Insights component already provides a built-in AzureInsightsApplicationEventSource class which automatically track these events. More importantly, Crosslight Azure Insights component already take care all the heavy-lifting behind the scene such as:

  • Store the events to the local storage when there's no Internet connection.
  • Monitoring the wifi connection availability and send the stored events to the web server when the connection becomes available.
  • Manage the queues to send the stored events in batch.

You can modify how the AzureInsightsApplicationEventSource works by implementing one of the following methods:

Finally, you register the IApplicationEventSource in your AppService using the following code.



 To learn more about application logging in Crosslight and see how it works, please checkout the following samples: