Skip to content

Commit aaab8cf

Browse files
committed
docs: sent test notification
1 parent e7c384e commit aaab8cf

File tree

2 files changed

+55
-28
lines changed

2 files changed

+55
-28
lines changed

README.md

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ The Honeybadger Notifier can be configured using the `HoneybadgerOptions` class.
1414
Honeybadger can be configured by passing the options when registering the service,
1515
or through your `appsettings.json` file.
1616

17-
Honeybadger, by default, will not report errors in development environments.
18-
You can override the development environments by setting the `DevelopmentEnvironments` property in the options.
19-
Alternatively, you can set the `ReportData` property to `true` to report errors in all environments.
20-
2117
See below for examples on how to configure Honeybadger for different types of applications.
2218

2319
### For .Net Core Web App
@@ -32,7 +28,10 @@ dotnet add package Honeybadger.DotNetCore
3228

3329
```c#
3430
var builder = WebApplication.CreateBuilder(args);
35-
builder.AddHoneybadger(new HoneybadgerOptions("{{PROJECT_API_KEY}}"));
31+
builder.AddHoneybadger(configure =>
32+
{
33+
configure.ApiKey = "{{PROJECT_API_KEY}}";
34+
});
3635
```
3736

3837
Or you can configure Honeybadger through your `appsettings.json` file, by adding a `Honeybadger` section:
@@ -46,6 +45,8 @@ Or you can configure Honeybadger through your `appsettings.json` file, by adding
4645
}
4746
}
4847
```
48+
**Note**: You should probably set your API key through environment variables or use the Secrets Manager, instead of hardcoding it in the `appsettings.json` file.
49+
You can read the [official documentation](https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets) for more information on how to do that in a .Net Core app.
4950

5051
And simply call `AddHoneybadger` without any parameters:
5152

@@ -59,15 +60,15 @@ builder.AddHoneybadger();
5960
You can access the _Honeybadger Client_ using _DI_:
6061

6162
```c#
62-
app.MapGet("/", ([FromServices] IHoneybadgerClient client) =>
63+
app.MapGet("/", ([FromServices] IHoneybadgerClient honeybadger) =>
6364
{
64-
client.AddBreadcrumb("reached index route", "route", new Dictionary<string, object?>());
65+
honeybadger.AddBreadcrumb("reached index route", "route", new Dictionary<string, object?>());
6566

6667
return "Hello World!";
6768
});
6869
```
6970

70-
Any unhandled exceptions should be reported to Honeybadger automatically (unless `ReportUnhandledExceptions` is set to false):
71+
Any unhandled exceptions should be reported to Honeybadger automatically (unless `ReportUnhandledExceptions` is set to `false`):
7172

7273
```c#
7374
app.MapGet("/debug", () =>
@@ -91,7 +92,10 @@ dotnet add package Honeybadger.Extensions.Logging
9192
```c#
9293
var builder = WebApplication.CreateBuilder(args);
9394
// or set the configuration in the appsettings.json file
94-
builder.AddHoneybadger(new HoneybadgerOptions("{{PROJECT_API_KEY}}"));
95+
builder.AddHoneybadger(configure =>
96+
{
97+
configure.ApiKey = "{{PROJECT_API_KEY}}";
98+
});
9599
builder.Logging.AddHoneybadger();
96100
```
97101

@@ -116,25 +120,12 @@ builder.AddHoneybadger();
116120
builder.Logging.AddHoneybadger();
117121
```
118122

119-
Note: If you want to disable automatic reporting of unhandled exceptions, you can set the `ReportUnhandledExceptions` property to `false` in the `HoneybadgerOptions`:
120-
121-
```json
122-
{
123-
"Honeybadger": {
124-
"ApiKey": "{{PROJECT_API_KEY}}",
125-
"AppEnvironment": "Development",
126-
"ReportData": true,
127-
"ReportUnhandledExceptions": false
128-
}
129-
}
130-
```
131-
132123
#### Usage
133124

134125
Errors from the `logger` will be reported to Honeybadger:
135126

136127
```c#
137-
app.MapGet("/notify", ([FromServices] ILogger logger) =>
128+
app.MapGet("/notify", ([FromServices] ILogger<Program> logger) =>
138129
{
139130
logger.LogError("hello from Honeybadger.Logger!");
140131

@@ -144,6 +135,42 @@ app.MapGet("/notify", ([FromServices] ILogger logger) =>
144135

145136
See example project in `examples/Honeybadger.DotNetCoreWebApp.Logger`.
146137

138+
### Send a test notification
139+
140+
**Note**: Honeybadger, by default, will not report errors in development environments.
141+
You can override the development environments by setting the `DevelopmentEnvironments` property in the options.
142+
Alternatively, you can set the `ReportData` property to `true` to report errors in all environments.
143+
144+
You can send a test notification to Honeybadger to verify that the configuration is working.
145+
Add the following to your `Program.cs` file:
146+
```c#
147+
// ...
148+
builder.AddHoneybadger();
149+
// ...
150+
var app = builder.Build();
151+
var honeybadger = app.Services.GetRequiredService<IHoneybadgerClient>();
152+
await honeybadger.NotifyAsync("Hello from .Net!");
153+
```
154+
155+
Run the app.
156+
If the configuration is correctly set, you should see the notification in your Honeybadger dashboard.
157+
158+
### Automatic Error Reporting
159+
160+
Automatic error reporting is enabled by default, but you can disable it by setting
161+
the `ReportUnhandledExceptions` property to `false` in `HoneybadgerOptions`:
162+
163+
```json
164+
{
165+
"Honeybadger": {
166+
"ApiKey": "{{PROJECT_API_KEY}}",
167+
"AppEnvironment": "Development",
168+
"ReportData": true,
169+
"ReportUnhandledExceptions": false
170+
}
171+
}
172+
```
173+
147174
### Using the SDK manually
148175

149176
#### 1. Install the [Honeybadger Nuget](https://www.nuget.org/packages/Honeybadger).
@@ -158,16 +185,16 @@ dotnet add package Honeybadger
158185
using Microsoft.Extensions.Options;
159186

160187
var options = new HoneybadgerOptions("{{PROJECT_API_KEY}}");
161-
var client = new HoneybadgerClient(Options.Create(options));
188+
var honeybadger = new HoneybadgerClient(Options.Create(options));
162189
```
163190

164191
#### 3. Call `notify` to report to Honeybadger:
165192

166193
```c#
167-
// blocking
168-
client.Notify("hello from .Net !");
194+
// fire and forget
195+
honeybadger.Notify("hello from .Net !");
169196
// or async
170-
await client.NotifyAsync("hello from .Net !");
197+
await honeybadger.NotifyAsync("hello from .Net !");
171198
```
172199

173200
See example project in `examples/Honeybadger.Console`.

examples/Honeybadger.Console/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
.Bind(options);
1616

1717
var client = new HoneybadgerClient(Options.Create(options));
18-
client.Notify("Hello from .Net! Improved error handling with Honeybadger.");
18+
await client.NotifyAsync("Hello from .Net! Improved error handling with Honeybadger.");
1919
Console.WriteLine("Done. Check your Honeybadger dashboard for the error.");

0 commit comments

Comments
 (0)