Skip to content

Commit 69e97e2

Browse files
committed
Add another sample usage to the values controller
1 parent 33059ed commit 69e97e2

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

samples/Exceptionless.SampleAspNetCore/Controllers/ValuesController.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class ValuesController : Controller {
1010
private readonly ILogger _logger;
1111

1212
public ValuesController(ExceptionlessClient exceptionlessClient, ILogger<ValuesController> logger) {
13+
// ExceptionlessClient instance from DI that was registered with the AddExceptionless call in Startup.ConfigureServices
1314
_exceptionlessClient = exceptionlessClient;
1415
_logger = logger;
1516
}
@@ -30,6 +31,15 @@ public Dictionary<string, string> Get() {
3031
handledException.ToExceptionless(_exceptionlessClient).Submit();
3132
}
3233

34+
try {
35+
throw new Exception($"Handled Exception (Default Client): {Guid.NewGuid()}");
36+
} catch (Exception handledException) {
37+
// Use the ToExceptionless extension method to submit this handled exception to Exceptionless using the default client instance (ExceptionlessClient.Default).
38+
// This works and is convenient, but its generally not recommended to use static singleton instances because it makes testing and
39+
// other things harder.
40+
handledException.ToExceptionless().Submit();
41+
}
42+
3343
// Unhandled exceptions will get reported since called UseExceptionless in the Startup.cs which registers a listener for unhandled exceptions.
3444
throw new Exception($"Unhandled Exception: {Guid.NewGuid()}");
3545
}
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
{
2-
"Exceptionless": {
3-
"ApiKey": "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw",
4-
"ServerUrl": "http://localhost:50000",
5-
"DefaultData": {
6-
"JSON_OBJECT": "{ \"Name\": \"Blake\" }",
7-
"Boolean": true,
8-
"Number": 1,
9-
"Array": "1,2,3"
10-
},
11-
"DefaultTags": [ "xplat" ],
12-
"Settings": {
13-
"FeatureXYZEnabled": false
14-
}
1+
{
2+
"Exceptionless": {
3+
"ApiKey": "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw",
4+
"ServerUrl": "http://localhost:50000",
5+
"DefaultData": {
6+
"JSON_OBJECT": "{ \"Name\": \"Blake\" }",
7+
"Boolean": true,
8+
"Number": 1,
9+
"Array": "1,2,3"
1510
},
16-
"Logging": {
17-
"IncludeScopes": false,
18-
"LogLevel": {
19-
"Default": "Debug",
20-
"System": "Information",
21-
"Microsoft": "Information"
22-
}
11+
"DefaultTags": [ "xplat" ],
12+
"Settings": {
13+
"FeatureXYZEnabled": false
2314
}
15+
},
16+
"Logging": {
17+
"LogLevel": {
18+
"Default": "Information",
19+
"Microsoft": "Warning",
20+
"Microsoft.Hosting.Lifetime": "Information"
21+
}
22+
},
23+
"AllowedHosts": "*"
2424
}

0 commit comments

Comments
 (0)