none
Application Insights Not Running In Local Mode RRS feed

  • Question

  • Hi everyone,

    While following the awesome beginners' course on MVA (At this location) I came to know about Application Insights being available for running in local mode. However, upon adding the same to my sample project I was surprised to find the activity to be showing 0's (zeros)?

    I am using the VS2017 Community.

    Following the tutorial:

    • I had right clicked the project
    • Selected Add > Application Insights Telemetry
    • Upon Application Insights Configuration Page selected Start Free
    • On the proceeding page I selected the option Or just add SDK to try local only mode at the bottom of page
    • Ran the application by pressing IIS Express
    • The Application Insights button I had added on the toolbar didn't show any number of activity
    • Upon clicking the said button the Application Insights Search page appeared, but with every event/result as 0 (Zero)

    At the same time I find the Immediate Window to be showing Application Insights Telemetry (unconfigured) at some places.

    The Startup file is as:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Logging;
    using Microsoft.EntityFrameworkCore;
    using Microsoft.Extensions.Configuration;
    
    namespace FAQ
    {
        public class Startup
        {
            public Startup(IConfiguration config)
            {
                configuration = config;
            }
    
            public IConfiguration configuration { get; }
    
            public void ConfigureServices(IServiceCollection services)
            {
                services.AddDbContext<FAQ_TempDB>(options => options.UseInMemoryDatabase("Some_Name"));
                services.AddLogging();
                services.AddMvc();
            }
    
            public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
            {
                loggerFactory.AddConsole();
                loggerFactory.AddDebug();
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
                app.UseStaticFiles();
                app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "default",
                        template: "{controller=Home}/{action=Index}/{id?}");
                });
            }
        }
    }

    while I have used it on the Create Model in a single CRUD page model as:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.RazorPages;
    using FAQ.Models;
    using Microsoft.EntityFrameworkCore;
    using Microsoft.Extensions.Logging;
    
    namespace FAQ.Pages
    {
        public class CreateModel : PageModel
        {
            private readonly FAQ_TempDB _TempDB;
    
            private ILogger<CreateModel> Log;
    
            public CreateModel(FAQ_TempDB tempDB, ILogger<CreateModel> log)
            {
                _TempDB = tempDB;
                Log = log;
            }
    
            [TempData]
            public string xMessage { get; set; }
    
            [BindProperty]
            public Worker Worker { get; set; }
    
            public async Task<IActionResult> OnPostAsync()
            {
                if (!ModelState.IsValid) {return Page();}
    
                _TempDB.Workers.Add(Worker);
                await _TempDB.SaveChangesAsync();
                var xMsg = $"Record of {Worker.W_FName} added!";
                xMessage = xMsg;
                Log.LogCritical(xMsg);      //THIS LOG ACTIVITY NOT WORKING ON APP INSIGHTS
                return RedirectToPage("/BackToDB");
            }
        }
    
        public class BackToDBModel : PageModel
        {
            private readonly FAQ_TempDB _TempDB;
    
            public BackToDBModel(FAQ_TempDB tempDB)
            {
                _TempDB = tempDB;
            }
    
            public IList<Worker> Workers { get; private set; }
    
            [TempData]
            public string xMessage { get; set; } //Name should be same as one declared in Create Model
    
            public async Task OnGetAsync()
            {
                Workers = await _TempDB.Workers.AsNoTracking().ToListAsync();
            }
    
            public async Task<IActionResult> OnPostDeleteAsync(int id)
            {
                var worker = await _TempDB.Workers.FindAsync(id);
                if (worker != null)
                {
                    _TempDB.Workers.Remove(worker);
                    await _TempDB.SaveChangesAsync();
                }
                return RedirectToPage();
            }
        }
    
        public class EditModel : PageModel
        {
            private readonly FAQ_TempDB _TempDB;
    
            public EditModel(FAQ_TempDB tempDB)
            {
                _TempDB = tempDB;
            }
    
            [BindProperty]
            public Worker Worker { get; set; }
    
            public async Task<IActionResult> OnGetAsync(int id)
            {
                Worker = await _TempDB.Workers.FindAsync(id);
                if (Worker == null)
                {
                    return RedirectToPage("/BackToDB");
                }
                return Page();
            }
    
            public async Task<IActionResult> OnPostAsync()
            {
                if (!ModelState.IsValid)
                {
                    return Page();
                }
    
                _TempDB.Attach(Worker).State = EntityState.Modified;
    
                try
                {
                    await _TempDB.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    throw new Exception($"Worker {Worker.W_FName} Not Found!", ex);
                }
                return RedirectToPage("/BackToDB");
            }
        }
    }


    The app works well on console reflecting the requisite critical portion in red but I don't understand why not on the local mode of Application Insights? Is it necessary to use Azure?

    Please see if any of you experts can help.

    Thanks.


    Thursday, December 28, 2017 7:38 AM