PHP code example of ercorp / ms-application-insights-monolog

1. Go to this page and download the library: Download ercorp/ms-application-insights-monolog library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ercorp / ms-application-insights-monolog example snippets



$logger  = new Monolog\Logger("Example");

$telemetryClient = new \ApplicationInsights\Telemetry_Client();
$telemetryClient->getContext()->setInstrumentationKey('YOUR INSTRUMENTATION KEY');

$msApplicationInsightsHandler = new \Marchie\MSApplicationInsightsMonolog\MSApplicationInsightsHandler($telemetryClient);

$logger->pushHandler($msApplicationInsightsHandler);

// The following error will get sent automatically to Microsoft Application Insights
$logger->addError("oh no!", array('exception' => new \Exception("ohnoception")));