You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
** Consider taking a look at the `samples` directory for different types of apps and example usages of the SDK. **
24
+
**Consider taking a look at the _[samples](https://github.com/getsentry/sentry-dotnet/tree/master/samples)_ directory for different types of apps and example usages of the SDK.**
25
+
26
+
This SDK provides integrations which can hook into your app and automatically capture errors and context.
27
+
28
+
## ASP.NET Core integration
29
+
30
+
To use Sentry with your ASP.NET Core project, simply install the NuGet package:
This will also automatically include the integration to `Microsoft.Extensions.Logging`. That means that any `LogError` or `LogCritical` by default will send an event to Sentry.
50
+
51
+
Log messages of level `Information` will be kept as _breadcrumbs_ and if an event is sent, all breadcrumbs from that transaction are included.
52
+
53
+
These levels can be configured so that the level you define tracks breadcrumbs or sends events or completely disable it.
54
+
55
+
**That means that log mesages logged by you or the framework, related to the failed transaction, will be added to the event!**
56
+
57
+
## DSN
58
+
59
+
The SDK needs to know which project within Sentry your errors should go to. That's defined via the [DSN](https://docs.sentry.io/quickstart/#configure-the-dsn). You can provide it directly as an argument to `UseSentry`, defined via configuration like `appsettings.json` or set via environment variable `SENTRY_DSN`.
60
+
[This sample demonstrates defining the DSN via `appsettings.json`](https://github.com/getsentry/sentry-dotnet/blob/f7f5c8cafcf2a54ccffeedb9ed0359c880b6aae5/samples/Sentry.Samples.AspNetCore.Mvc/appsettings.json#L6).
61
+
62
+
## Configuration
63
+
64
+
The SDK is configurable, many of the settings are demonstrated through the samples but here are some options:
21
65
22
-
The goal of this SDK is to provide integrations which can hook into your app and automatically capture errors and context. See ASP.NET Core below as an example.
* BeforeSend: Callback to modify/reject event before sending
71
+
* LogEventFilter: Filter events by inspecting log data
72
+
* Maximum number of breadcrumbs to store
73
+
* Event queue depth
74
+
* Shutdown timeout: If there are events to send, how long to wait until shutdown
75
+
* Accept compressed response
76
+
* Compress request body
77
+
* Breadcrumb level: Minimal log level to store as a breadcrumb
78
+
* Event level: Minimal log level to send an event to Sentry
23
79
24
-
You can still use the SDK directly to send events to Sentry:
80
+
and more...
81
+
82
+
## Microsoft.Extensions.Logging
83
+
84
+
If you want only the logging integration:
85
+
```shell
86
+
dotnet add package Sentry.Extensions.Logging
87
+
```
88
+
See the [logging integration only sample](https://github.com/getsentry/sentry-dotnet/blob/master/samples/Sentry.Samples.ME.Logging/Program.cs)
89
+
90
+
91
+
## Without any framework integration
92
+
You can still use the SDK directly to send events to Sentry.
93
+
There's a [basic sample](https://github.com/getsentry/sentry-dotnet/blob/master/samples/Sentry.Samples.Console.Basic/Program.cs) and a one demonstrating [more customization](https://github.com/getsentry/sentry-dotnet/blob/master/samples/Sentry.Samples.Console.Customized/Program.cs).
To use Sentry with your ASP.NET Core project, simply install the NuGet package:
145
+
It's often the case we don't want to couple our code with static class like `SentrySdk`, especially to allow our code to be testable.
146
+
If that's your case, you can use 2 abstractions:
77
147
78
-
```shell
79
-
dotnet add package Sentry.AspNetCore
80
-
```
148
+
* ISentryClient
149
+
* IHub
81
150
82
-
Change your `Program.cs` by adding `UseSentry`:
151
+
The `ISentryClient` is responsible to queueing the event to be sent to Sentry and abstracting away the internal transport.
152
+
The `IHub` on the other hand, holds a client and the current scope. It in fact also implements `ISentryClient` and is able to dispatch calls to the right client depending on the current scope.
In order to allow different events hold different contextual data, you need to know in which scope you are in.
155
+
That's the job of the `Hub`. It holds the scope management as well as a client.
93
156
94
-
This will also include automatically integration to `Microsoft.Extensions.Logging`. That means that any `LogError` or `LogCritical` by default will send an event to Sentry.
95
-
Log messages of level `Information` will be kept as _breadcrumbs_ and if an event is sent, all breadcrumbs from that transaction are included.
157
+
If all you are doing is sending events, without modification/access to the current scope, then you depend on `ISentryClient`. If on the other hand you would like to have access to the current scope by configuring it or binding a different client to it, etc. You'd depend on `IHub`.
96
158
97
-
These levels can be configured so that the level you define tracks breadcrumbs or sends events or completely disable it.
159
+
160
+
An example using `IHub` for testability is [SentryLogger](https://github.com/getsentry/sentry-dotnet/blob/master/src/Sentry.Extensions.Logging/SentryLogger.cs) and its unit tests [SentryLoggerTests](https://github.com/getsentry/sentry-dotnet/blob/master/test/Sentry.Extensions.Logging.Tests/SentryLoggerTests.cs).
161
+
`SentryLogger` depends on `IHub` because it does modify the scope (through `AddBreadcrumb`). In case it only sent events, it should instead depend on `ISentryClient`
162
+
163
+
## Compatibility
164
+
165
+
The packages target **.NET Standard 2.0**. That means [it is compatible with](https://docs.microsoft.com/en-us/dotnet/standard/net-standard) the following versions or newer:
166
+
167
+
* .NET Framework 4.6.1
168
+
* .NET Core 2.0
169
+
* Mono 5.4
170
+
* Xamarin.Android 8.0
171
+
* Xamarin.Mac 3.8
172
+
* Xamarin.iOS 10.14
173
+
* Universal Windows Platform 10.0.16299
174
+
175
+
Of those, we've tested (we run our unit/integration tests) against:
176
+
177
+
* .NET Framework 4.6.2 on Windows (AppVeyor)
178
+
* Mono 5.12 macOS and Linux (Travis-CI)
179
+
* .NET Core 2.0 Windows (AppVeyor), macOS and Linux (Travis-CI)
180
+
* .NET Core 2.1 Windows (AppVeyor), macOS and Linux (Travis-CI)
181
+
182
+
183
+
### Legacy frameworks
184
+
185
+
Sentry's [Raven SDK](https://github.com/getsentry/raven-csharp/), battle tested with over 300.000 downloads on NuGet has support to .NET Framework 3.5+.
<Description>Official ASP.NET Core integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
<Description>Official Microsoft.Extensions.Logging integration for Sentry - Open-source error tracking that helps developers monitor and fix crashes in real time.</Description>
0 commit comments