How to catch an error in an MVC 5 method using Application Insights


i have installed application insights mvc 5 asp.net 4.5 app. sending kinds of data portal. now, want see if can use catch specific error that's happening in method.

 public async task<merchant> updateasync(merchant merchant)
        {
            using (var uow = _unitofworkfactory.create())
            {
                uow.merchantrepository.update(merchant);
                await uow.savechangesasync();

                return merchant;
            }
        }

i'm trying catch error in method.

public async task<actionresult> getofferslist(guid id)
        {
           
                var consumer = await _merchantconsumerservice.findasync(id);
                var model = await _uniqueofferservice.getconsumerofferssummaryasync(consumer.consumerid);
                return partialview("_consumerofferslistpartial", model);
           
        }

how go using application insights catch , report errors? use try , catch on app, i've read documentation on ai , don't understand how implement in code.

any appreciated. thanks!

 

hi,

i'll try explain above example - after installing application insights nuget, can create telemetryclient, used send telemetry events application insights backend.

to so, create telemetryclient in catch block:

var telemetryclient = new telemetryclient();

and report exception:

telemetryclient.trackexception(ex);

when exception send application insights backend, able see in azure portal in application insights resource, including full stack trace should investigate root cause.

you can set applications instrumentation key (to indicate specific application insights resource) running following in startup.cs:

telemetryconfiguration.active.instrumentationkey = “ikey”; 

please let me know if better understand whats going on.

thanks,

asaf



Visual Studio Development  ,  Visual Studio Team Foundation Server  >  Application Insights (AI)



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'