2015年12月6日 星期日

[Open Source] Use Exceptionless to monitor the application

 #Exceptionless   #Elasticssearch   #NLog 


Introduction


Exceptionless is an open source product, which provides real time reporting for errors, features and logs.

For more reference, here are their great website and GitHub.




Background

The first job in my new position as a DevOps was building the CI process for developers, including of the log handling. 

However, the supervisors and boss always want more. If there are some dashboards and reports for the application logs, that will be pretty cool.


So I found that the solutions went easily with Exceptionless! My hero!




Before we start


Download

JDK

elasticsearch

Exceptionless
    The latest version must run on .NET framework 4.6

    elasticsearch.yml is the config for elasticsearch
    However, you can get elasticsearch.yml within the package of Exceptionless release.

Exceptionless.UI
Exceptionless.UI will host a website for dashboards and user controls.




Install and Setup

JRE

Set the system variable for JAVA_HOME.



elasticsearch

First, we must use the elasticsearch.yml of Exceptionless to override the original config at elasticsearch-{version}\config\elasticsearch.yml



Note that I found the latest elasticsearch.yml of Exceptionless (3.1.1822) won’t work fine on the latest version : 2.1.0, of elasticsearch.
But it was ok with elasticsearch 1.7.2 !

The error message on elasticsearch 2.1.0 … (looks like some conflict issues.)



So I used elasticsearch 1.7.2 instead.



Then we could run elasticsearch as a service in Windows.
Use the following command to register a service.

service.bat install [Service Id]

PS. You can also remove/start/stop the service.

 

 

Make a simple check if the service is ok by Http Get :
http://localhost:9200/




Build the Exceptionless Server


IIS 

Create two websites for Exceptionless (port:5100) and Exceptionless.UI (port:5000)
    The websites should run with application pool of .NET framework 4.0.
    Make sure the ports are allowed in firewall.

 


Exceptionless

Copy the Exceptionless\release ‘s files in folder wwwroot into our IIS website : Exceptionless.

 

Update Web.config ,

l   Elasticsearch uri

<add name="ElasticSearchConnectionString" connectionString="http://localhost:9200" />


l   Exceptionless service uri

<add key="BaseURL" value="http://localhost:5100/#" />


l   Enable SSL (Optional)

<add key="EnableSSL" value="false" />


l   WebsiteMode
It can be “Dev”, “QA” or “Production” , depends on your environment.

<add key="WebsiteMode" value="Dev" />


l   Exceptionless.UI uri

<add key="Exceptionless:ServerUrl" value="http://localhost:5000" />



Open app.config.*

Modify the parameters,

l   Exceptionless uri

'BASE_URL', 'http://localhost:5100'


l   Enable HTML5 mode

'USE_HTML5_MODE', false


l   SSL

'USE_SSL', false





Exceptionless.UI

Copy the Exceptionless.UI\release ‘s files into our IIS website : Exceptionless.UI




Open app.config.*

Modify the parameters,

l   Exceptionless uri

'BASE_URL', 'http://localhost:5100'


l   Enable HTML5 mode

'USE_HTML5_MODE', false


l   SSL

'USE_SSL', false




Get started with Exceptionless!

Okay, we had deployed the Exceptionless service and Exceptionless.UI (GUI).
Link to Exceptionless.UI, you might get the following exception.



Yes, the error message told us that we had to grant IIS permission to Exceptionless\App_Data\

After everything is done, we can sign up in the Exceptionless server!

 


First of all, we have to create a project.

 

Setup the project and get the API_KEY.

 


Run the client with Exceptionless


Client example (Console)

In the Console project of Visual Studio, install the package below.

 

l   Set the App.Config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="exceptionless" type="Exceptionless.ExceptionlessSection, Exceptionless.Extras" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <exceptionless apiKey="XXXX" enableLogging="true" logPath="C:\temp\exceptionless.log" />
</configuration>


l   Main Program : Register a Exceptionless Client

var client = new ExceptionlessClient(config => {
     // Set your API key. (Optional if the config is set)
     config.ApiKey = "XXXXXX";
// Exceptionless server.
    config.ServerUrl = "http://localhost:5100/";
    // Read config settings from attributes.
    config.ReadFromAttributes();
// Exclude any form fields, cookies, query string parameters, and custom data properties containing "CompanyPrivate".
    //config.AddDataExclusions("CompanyPrivate");

// Add the "SomeTag" to all events.
    config.DefaultTags.Add("Test");

    // Add the "MyObject" custom data object to every event.
    //config.DefaultData.Add("MyObject", new { MyProperty = "Value1" });

    // Register a custom log implementation that uses NLog.
    //config.Resolver.Register<IExceptionlessLog>(new NLogExceptionlessLog());
});

client.Register();



l   Main Program : Sending Message

I will use the examples of Exceptionless Document.

// Submit logs
client.SubmitLog("Logging made easy");

// You can also specify the log source and log level.
// We recommend specifying one of the following log levels: Trace, Debug, Info, Warn, Error
client.SubmitLog(typeof(Program).FullName, "This is so easy", "Info");
client.CreateLog(typeof(Program).FullName, "This is so easy", "Info").AddTags("Exceptionless").Submit();

// Submit feature usages
client.SubmitFeatureUsage("MyFeature");
client.CreateFeatureUsage("MyFeature").AddTags("Exceptionless").Submit();

// Submit a 404
client.SubmitNotFound("/somepage");
client.CreateNotFound("/somepage").AddTags("Exceptionless").Submit();

// Submit a custom event type
client.SubmitEvent(new Event { Message = "Low Fuel", Type = "racecar", Source = "Fuel System" });

try
{   throw new ApplicationException(Guid.NewGuid().ToString()); }
catch (Exception ex)
{   ex.ToExceptionless(client:client).Submit();  }



Results :

(All events)

(Exceptions)
 


Logger Integation

We can integrate Logger and Exceptionless. Take NLog for example.
Add the two packages into our Visual Studio project.

 



Update NLog.config

<extensions>
    <add assembly="Exceptionless.NLog" />
  </extensions>
<targets>
<target name="Exceptionless" xsi:type="Exceptionless" apiKey="XXXXXX" serverUrl="http://localhost:5100/">
      <field name="host" layout="${machinename}" />
      <field name="identity" layout="${identity}" />
      <field name="windows-identity" layout="${windows-identity:userName=True:domain=False}" />
      <field name="process" layout="${processname}" />
    </target>
  </targets>
<rules>
<logger name="*" levels="Trace, Debug, Info, Warn, Error, Fatal" writeTo="Exceptionless" />
</rules>


Now the logs could be sent to Exceptionless server like the following picture.

 



Reference








沒有留言:

張貼留言