Skip to content

Commit 12e31a4

Browse files
committed
Update sample app
Sample app itself update itself.
1 parent cdded3d commit 12e31a4

File tree

2 files changed

+117
-43
lines changed

2 files changed

+117
-43
lines changed

README.md

Lines changed: 73 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ To send an exception to Trakerr, it's as simple as calling .SendToTrakerr() on t
4040
```csharp
4141
using IO.TrakerrClient;
4242
using System;
43-
using System.Collections.Generic;
44-
using System.Linq;
45-
using System.Text;
46-
using System.Threading.Tasks;
4743

4844
namespace TrakerrSampleApp
4945
{
@@ -68,14 +64,13 @@ namespace TrakerrSampleApp
6864
}
6965
```
7066

71-
### Option-2: Send an exception with custom properties to Trakerr
67+
### Option-2: Send an exception using the TrakerrClient
68+
The benifit of using the TrakerrClient to automatically create and send your error, as opposed to above, is that you can change the log level. You will, however, have to also add an import.
69+
7270
```csharp
7371
using IO.TrakerrClient;
72+
using IO.Trakerr.Model;
7473
using System;
75-
using System.Collections.Generic;
76-
using System.Linq;
77-
using System.Text;
78-
using System.Threading.Tasks;
7974

8075
namespace TrakerrSampleApp
8176
{
@@ -88,18 +83,55 @@ namespace TrakerrSampleApp
8883
{
8984
var client = new TrakerrClient();
9085

91-
try {
92-
...
93-
} catch(Exception e) {
94-
var exceptionEvent = client.CreateAppEventFromException("Error", e);
86+
try
87+
{
88+
throw new ArgumentException("Args are invalid.");
89+
}
90+
catch (Exception e)
91+
{
92+
tc.SendException(e);//Can also change the log level, along with the classifcation, unlike the above which only changes issue.
93+
}
94+
}
95+
}
96+
}
97+
```
98+
99+
### Option-3: Send an exception using the TrakerrClient
100+
You can get an appevent to change and store custom data. You must then call to manually send it afterwards.
101+
102+
```csharp
103+
using IO.TrakerrClient;
104+
using IO.Trakerr.Model;
105+
using System;
95106

96-
exceptionEvent.CustomProperties = new IO.Trakerr.Model.CustomData();
97-
exceptionEvent.CustomProperties.StringData = new IO.Trakerr.Model.CustomStringData();
98-
exceptionEvent.CustomProperties.StringData.CustomData1 = "Some custom data";
107+
namespace TrakerrSampleApp
108+
{
109+
/// <summary>
110+
/// Sample program to generate an event
111+
/// </summary>
112+
class Program
113+
{
114+
static void Main(string[] args)
115+
{
116+
var client = new TrakerrClient();
99117

100-
client.SendEventAsync(exceptionEvent);
118+
try
119+
{
120+
throw new IndexOutOfRangeException("Buffer overflow.");
101121
}
122+
catch (Exception e)
123+
{
124+
var appevent = tc.CreateAppEvent(e, AppEvent.LogLevelEnum.Fatal);//Can also change the classification.
125+
//EventType and EventMessage are set automatically by create app event; you can set them manually from the appevent instance too.
126+
appevent.EventUser = "john@trakerr.io";
127+
appevent.EventSession = "8";
102128

129+
appevent.CustomProperties = new CustomData();
130+
appevent.CustomProperties.StringData = new CustomStringData("This is string data 1!");//Add up to 10 custom strings.
131+
appevent.CustomProperties.StringData.CustomData2 = "This is string data 2!";//You can also add strings later like this.
132+
133+
tc.SendEventAsync(appevent);
134+
}
103135
}
104136
}
105137
}
@@ -108,13 +140,12 @@ namespace TrakerrSampleApp
108140

109141

110142
### Option-3: Send any event (including non-exceptions) programmatically
143+
You can send non-errors to Trakerr. This will send an event without a stacktrace. Be sure to construct the object properly as the default values in `CreateAppEvent` may not be useful for your non-error.
144+
111145
```csharp
112146
using IO.TrakerrClient;
147+
using IO.Trakerr.Model;
113148
using System;
114-
using System.Collections.Generic;
115-
using System.Linq;
116-
using System.Text;
117-
using System.Threading.Tasks;
118149

119150
namespace TrakerrSampleApp
120151
{
@@ -127,9 +158,13 @@ namespace TrakerrSampleApp
127158
{
128159
var client = new TrakerrClient();
129160

130-
var event = client.CreateAppEvent("Info", "System.Exception", "Some message");
161+
var infoevent = tc.CreateAppEvent(AppEvent.LogLevelEnum.Info, "User sends clicked this button", "Feature Analytics", "Some Feature");
162+
infoevent.EventUser = "jill@trakerr.io";
163+
infoevent.EventSession = "2";
164+
165+
//Populate any other data you want, customdata or overriding default values of the appevent.
131166
132-
client.SendEventAsync(event);
167+
tc.SendEventAsync(infoevent);
133168
}
134169
}
135170
}
@@ -140,27 +175,26 @@ namespace TrakerrSampleApp
140175
The `TrakerrClient` class above can be constructed to take aditional data, rather than using the configured defaults. The constructor signature is:
141176

142177
```csharp
143-
public TrakerrClient(string apiKey = null, string url = null, string contextAppVersion = null,
144-
string contextEnvName = "development", string contextEnvVersion = null,
145-
string contextEnvHostname = null, string contextAppOS = null,
146-
string contextAppOSVersion = null, string contextDataCenter = null,
147-
string contextDataCenterRegion = null)
178+
public TrakerrClient(string apiKey = null, string contextAppVersion = null, string contextDeploymentStage = null, string contextEnvLanguage = "C#")
148179
```
149180

150181
Nearly all of these have default values when passed in `null`. Below is a list of the arguments, and what Trakerr expects so you can pass in custom data.
151182

152183
Name | Type | Description | Notes
153-
------------ | ------------- | ------------- | -------------
154-
**apiKey** | **str** | API Key for your application. | Defaults to reading "trakerr.apiKey" property under appSettings from the App.config.
155-
**url** | **str** | URL to Trakerr. | Defaults to reading "trakerr.url" property under appSettings from the App.config.
156-
**contextAppVersion** | **str** | Provide the application version. | Defaults to reading "trakerr.contextAppVersion" property under appSettings from the App.config.
157-
**contextEnvName** | **str** | Provide the environemnt name (development/staging/production). You can also pass in a custom name. | Defaults to reading "trakerr.contextEnvName" property under appSettings from the App.config.
158-
**contextEnvVersion** | **str** | (Optional) Provide an optional context environment version. | Defaults to `null`.
159-
**contextEnvHostname** | **str** | Provide the current hostname. | Defaults to the current DNS name if available or uses the Machine name as a fallback.
160-
**contextAppOS** | **str** | Provide an operating system name. | Defaults to Environment.OSVersion.Platform along with the service pack (eg. Win32NT Service Pack 1).
161-
**contextAppOSVersion** | **str** | Provide an operating system version. | Defaults to Environment.OSVersion.Version.ToString() (eg. 6.1.7601.65536).
162-
**contextDataCenter** | **str** | (optional) Provide a datacenter name. | Defaults to `null`.
163-
**contextDataCenterRegion** | **str** | (optional) Provide a datacenter region. | Defaults to `null`.
184+
------------ | ------------- | ------------- | -------------
185+
**apiKey** | **string** | API Key for your application. | Defaults to reading "trakerr.apiKey" property under appSettings from the App.config.
186+
**contextAppVersion** | **string** | Provide the application version. | Defaults to reading "trakerr.contextAppVersion" property under appSettings from the App.config.
187+
**contextDevelopmentStage** | **string** | One of development, staging, production; or a custom string. | Default Value: trakerr.deploymentStage or "development" if not provided.
188+
**contextEnvLanguage** | **string** | Constant string representing the language the application is in. | Default value: "ruby"
189+
**contextEnvName** | **string** | Name of the CLR the program is running on | Defaults to returning "Microsoft CLR" if using .Net framework or "Mono" if mono.
190+
**contextEnvVersion** | **string** | Provide an environment version. | Defaults to reading to the CLR version of .net, or uses reflection to find the mono version.
191+
**contextEnvHostname** | **string** | Provide the current hostname. | Defaults to the current DNS name if available or uses the Machine name as a fallback.
192+
**contextAppOS** | **string** | Provide an operating system name. | Defaults to Environment.OSVersion.Platform along with the service pack (eg. Win32NT Service Pack 1).
193+
**contextAppOSVersion** | **string** | Provide an operating system version. | Defaults to Environment.OSVersion.Version.ToString() (eg. 6.1.7601.65536).
194+
**contextAppOSBrowser** | **string** | An optional string browser name the application is running on. | Defaults to `null`
195+
**contextAppOSBrowserVersion** | **string** | An optional string browser version the application is running on. | Defaults to `null`
196+
**contextDataCenter** | **string** | Data center the application is running on or connected to. | Defaults to `null`
197+
**contextDataCenterRegion** | **string** | Data center region. | Defaults to `null`
164198

165199
If you want to use a default value in a custom call, simply pass in `null` to the argument, and it will be filled with the default value.
166200

TrakerrSampleApp/Program.cs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using IO.TrakerrClient;
2+
using IO.Trakerr.Model;
23
using System;
3-
using System.Reflection;
4-
using Microsoft.Win32;
54

65
namespace TrakerrSampleApp
76
{
@@ -12,6 +11,7 @@ class Program
1211
{
1312
static void Main(string[] args)
1413
{
14+
//Option 1: Send to Trakerr automatically.
1515
try
1616
{
1717

@@ -22,8 +22,48 @@ static void Main(string[] args)
2222
// Send the event to Trakerr
2323
e.SendToTrakerr();
2424
}
25-
Console.Out.WriteLine("Done!");
26-
Console.In.ReadLine();//Give time for the Async tasks to print to console.
25+
26+
//Option 2: Send to Trakker using the client API.
27+
TrakerrClient tc = new TrakerrClient();
28+
29+
try
30+
{
31+
throw new ArgumentException("Args are invalid.");
32+
}
33+
catch (Exception e)
34+
{
35+
tc.SendException(e);//Can also change the log level, along with the classifcation, unlike the above which only changes issue.
36+
}
37+
38+
//Option 3: Send an exception to Trakerr with custom data.
39+
try
40+
{
41+
throw new IndexOutOfRangeException("Buffer overflow.");
42+
}
43+
catch (Exception e)
44+
{
45+
var appevent = tc.CreateAppEvent(e, AppEvent.LogLevelEnum.Fatal);//Can also change the classification.
46+
//EventType and EventMessage are set automatically by create app event; you can set them manually from the appevent instance too.
47+
appevent.EventUser = "john@trakerr.io";
48+
appevent.EventSession = "8";
49+
50+
appevent.CustomProperties = new CustomData();
51+
appevent.CustomProperties.StringData = new CustomStringData("This is string data 1!");//Add up to 10 custom strings.
52+
appevent.CustomProperties.StringData.CustomData2 = "This is string data 2!";//You can also add strings later like this.
53+
54+
tc.SendEventAsync(appevent);
55+
}
56+
57+
//Option 4: Send a non-exception to Trakerr.
58+
var infoevent = tc.CreateAppEvent(AppEvent.LogLevelEnum.Info, "User sends clicked this button", "Feature Analytics", "Some Feature");
59+
infoevent.EventUser = "jill@trakerr.io";
60+
infoevent.EventSession = "2";
61+
62+
//Populate any other data you want, customdata or overriding default values of the appevent.
63+
64+
tc.SendEventAsync(infoevent);
65+
66+
Console.In.ReadLine();//Give time for the Async tasks to print to console for the sample app.
2767
}
2868
}
2969
}

0 commit comments

Comments
 (0)