Application Insights with NLog

  • November 2, 2017

    By Andrew Cook

    Andrew Cook is a Software Development Consultant specializing in helping organizations migrate and develop applications that leverage the power of Microsoft Azure.

    Why Application Insights with NLog?

    Application insights is Microsoft’s analytics and diagnostics application service. This allows for real time and historical monitoring of an application reducing outages and improving resolution time when errors occur. Paired with NLog, an open-source logging for .Net, allows a developer to capture application failures as well as include custom messages and data to enhance application logging. As a .NET Developer, I have used this to understand the health of my application quickly when a user reports an issue and has saved countless hours of searching through various log files.

    One of the things I love with programming is debugging. On my recent projects, I have implemented logging via NLog with Application Insights which greatly improves my debugging time.

    For that project I was developing a .NET web application with Visual Studio 2017 and Azur. Here are the steps I took to implement logging via NLog.

    Part 1: Configuring your application to use Application Insights and send data to Azure

    1. Open your application.
    2. Right click on the solution and select Manage NuGet Packages for Solution
    3. Click on the Browse Tab and type NLog
    4. Select your projects and click Install.
    5. Right click on your project and select Application Insights and then Configure application insights.
    6. Select your Azure subscription and resource group.
    7. To prevent any charges for Application Insights, select the option of “Application Insights will remain free and halt data collection after 1GB/Month.” And then click Register. (Please don’t choose this option for a production application!)

    At this point your application is now configured to use Application Insights and send the data to Azure.

    Part 2: Add logging via NLog

    1. Open the HomeController.cs file
    2. Add using NLog; to the top of the file.
    3. Finally deploy you application and within a few minutes you will see debug data available in Application Insights on Azure.

     

    Full source code available: GitHub

     

    To learn more about Andrew follow him on twitter @codingwcookie or browse his personal blog https://codingwithcookie.com

    Comments(0)

    Leave a comment

    Required fields are marked *