Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/collections/_documentation/learn/before-send/csharp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
A `Func<SentryEvent, SentryEvent>` can be used to mutate, discard (return null), or return a completely new event.

```csharp
using Sentry;

SentrySdk.Init(o =>
{
o.BeforeSend = sentryEvent =>
{
// Modify the event here:
sentryEvent.ServerName = null; // Don't send server names.
return sentryEvent;
};
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```csharp
using Sentry;

SentrySdk.AddBreadcrumb(
message: "Authenticated user " + user.email,
category: "auth",
level: BreadcrumbLevel.Info);
```
2 changes: 1 addition & 1 deletion src/collections/_documentation/learn/breadcrumbs.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ to record a breadcrumb if the user authenticates or another state change happens
## Automatic Breadcrumbs

SDKs will automatically start recording breadcrumbs by enabling integrations. For instance
the browser JavaScript SDK will automatically record all lcoation changes.
the browser JavaScript SDK will automatically record all location changes.
9 changes: 6 additions & 3 deletions src/collections/_documentation/learn/capture-error/csharp.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
In .NET you can capture any exception object that you caught:
In C# you can capture any exception object that you caught:

```csharp
using Sentry;

try {
try
{
AFunctionThatMightFail();
} catch (Exception err) {
}
catch (Exception err)
{
SentrySdk.CaptureException(err);
}
```
4 changes: 2 additions & 2 deletions src/collections/_documentation/learn/config-intro/csharp.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Options can be set by passing a callback to the `Init()` function which will
Options can be set by passing a callback to the `Init()` method which will
pass the option object along for modifications:

```javascript
```csharp
using Sentry;

using (SentrySdk.Init(o =>
Expand Down
17 changes: 14 additions & 3 deletions src/collections/_documentation/learn/configure-scope/csharp.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
```javascript
```csharp
using Sentry;

SentrySdk.ConfigureScope(scope => {
SentrySdk.ConfigureScope(scope =>
{
scope.SetTag("my-tag", "my value");
scope.User = new User {
scope.User = new User
{
Id = "42",
Email = "john.doe@example.com"
};
});
```

Or when an asynchronous call is required:

```csharp
await SentrySdk.ConfigureScopeAsync(scope =>
{
scope.User = await _context.Users.FindAsync(id);
});
```
4 changes: 2 additions & 2 deletions src/collections/_documentation/learn/scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ nitty gritty details. On platforms such as .NET or on Python 3.7 and later we w
use "ambient data" to have either the hub flow with your code or the hub is already
a singleton that internally manages the scope.

Effectively this means that when you spawn a task in .NET and the execution flow is
Effectively this means that when you spawn a task in .NET and the execution flow is
not supressed all the context you have bound to the scope in Sentry will flow along.
If however you surpress the flow you get new scope data.
If however you suppress the flow, you get new scope data.
{% endcapture %}
{%- include components/alert.html
title="Note"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```csharp
using Sentry;

SentrySdk.Init(o => o.Environment = "{{ page.example_environment }}");
```
8 changes: 8 additions & 0 deletions src/collections/_documentation/learn/set-extra/csharp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```csharp
using Sentry;

SentrySdk.ConfigureScope(scope =>
{
scope.SetExtra("{{ page.example_extra_key }}", "{{ page.example_extra_value }}");
});
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```csharp
using Sentry;

SentrySdk.ConfigureScope(scope =>
{
scope.SetFingerprint(new[] { "my-view-function" });
});
```
5 changes: 5 additions & 0 deletions src/collections/_documentation/learn/set-release/csharp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
```csharp
using Sentry;

SentrySdk.Init(o => o.Release = "{{ page.release_identifier }}");
```
8 changes: 8 additions & 0 deletions src/collections/_documentation/learn/set-tag/csharp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
```csharp
using Sentry;

SentrySdk.ConfigureScope(scope =>
{
scope.SetTag("{{ page.example_tag_name }}", "{{ page.example_tag_value }}");
});
```
11 changes: 11 additions & 0 deletions src/collections/_documentation/learn/set-user/csharp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```csharp
using Sentry;

SentrySdk.ConfigureScope(scope =>
{
scope.User = new User
{
Email = "john.doe@example.com"
};
});
```
83 changes: 83 additions & 0 deletions src/collections/_documentation/platforms/dotnet/entityframework.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: EntityFramework
sidebar_order: 8
---

Sentry has an integration with `EntityFramework` through the of the `Sentry.EntityFramework` NuGet package.

> Looking for `EntityFramework Core`? That integration is achieved through the `Microsoft.Extensions.Logging` package.


## Installation

Using package manager:

```powershell
Install-Package Sentry.EntityFramework
```

Or using the .NET Core CLI:

```sh
dotnet add Sentry.EntityFramework
```

This package extends `Sentry` main SDK. That means that besides the EF features, through this package you'll also get access to all API and features available in the main `Sentry` SDK.

## Features

* Queries as breadcrumbs
* Validation errors

All queries executed are added as breadcrumbs and are sent with any event which happens on the same `Scope`. Besides that, validation errors are also included as `Extra`.


## Configuration

There are 2 steps to adding Entity Framework 6 support to your project:

* Call `SentryDatabaseLogging.UseBreadcrumbs()` to either your application's startup method, or into a static constructor inside your Entity Framework object. Make sure you only call this method once! This will add the interceptor to Entity Framework to log database queries.
* When initializing the SDK, call the extension method `AddEntityFramework()` on `SentryOptions`. This will register all error processors to extract extra data, such as validation errors, from the exceptions thrown by Entity Framework.

### Example configuration

For example, configuring an ASP.NET app with _global.asax_:

```csharp
public class MvcApplication : System.Web.HttpApplication
{
private IDisposable _sentrySdk;

protected void Application_Start()
{
// We add the query logging here so multiple DbContexts in the same project are supported
SentryDatabaseLogging.UseBreadcrumbs();
_sentrySdk = SentrySdk.Init(o =>
{
// We store the DSN inside Web.config
o.Dsn = new Dsn(ConfigurationManager.AppSettings["SentryDsn"]);
// Add the EntityFramework integration
o.AddEntityFramework();
});
}

// Global error catcher
protected void Application_Error()
{
var exception = Server.GetLastError();
SentrySdk.CaptureException(exception);
}

public override void Dispose()
{
_sentrySdk.Dispose();
base.Dispose();
}
}
```

### Sample

Check out a complete working [sample](https://github.com/getsentry/sentry-dotnet-ef/tree/master/samples/Sentry.Samples.AspNet.Mvc) to see it in action.

![Sample breadcrumbs in Sentry](https://github.com/getsentry/sentry-dotnet-ef/blob/master/.assets/ef.PNG?raw=true)
50 changes: 50 additions & 0 deletions src/collections/_documentation/platforms/dotnet/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: .NET
sidebar_order: 10
---

This section will describe features, configurations and general functionality which are specific to the .NET SDKs.

### Code


#### Automatically discovering release version

The SDK attempts to locate the release to add that to the events sent to Sentry.

> [Default values like 1.0 or 1.0.0.0 are ignored](https://github.com/getsentry/sentry-dotnet/blob/dbb5a3af054d0ca6f801de37fb7db3632ca2c65a/src/Sentry/Internal/ApplicationVersionLocator.cs#L14-L21).

The SDK will firstly look at the [entry assembly's](https://msdn.microsoft.com/en-us/library/system.reflection.assembly.getentryassembly(v=vs.110).aspx) `AssemblyInformationalVersionAttribute`, which accepts a string as
value and is often used to set a GIT commit hash.

If that returns null, it'll look at the default `AssemblyVersionAttribute` which accepts the numeric version number. When creating a project with Visual Studio, that values is set to *1.0.0.0*.
Since that usually means that the version is either not being set, or is set via a different method. The **automatic version detection will disregard** this value and no *Release* will be reported automatically.

#### Unit testing

We often don't want to couple our code with static class like `SentrySdk`. Especially to allow our code to be testable.
If that's your case, you can use 2 abstractions:

* `ISentryClient`
* `IHub`

The `ISentryClient` exposes the `CaptureEvent` method and it's implementation `SentryClient` is responsible to queueing the event to be sent to Sentry. It also abstracts away the internal transport.

The `IHub` on the other hand, holds a client and the current scope. In fact, it extends `ISentryClient` and is able to dispatch calls to the right client depending on the current scope.

In order to allow different events to hold different contextual data, you need to know in which scope you are in.
That's the job of the [`Hub`](https://github.com/getsentry/sentry-dotnet/blob/master/src/Sentry/Internal/Hub.cs). It holds the scope management as well as a client.

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, you depend on `IHub`.


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).
`SentryLogger` depends on `IHub` because it does modify the scope (through `AddBreadcrumb`). In case it only sent events, it should instead depend on `ISentryClient`


#### Integrations

ASP.NET Core
Microsoft.Extensions.Logging
log4net
Entity Framework 6
57 changes: 57 additions & 0 deletions src/collections/_documentation/platforms/dotnet/log4net.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: log4net
sidebar_order: 10
---

Sentry has an integration with log4net through the `Sentry.Log4Net` NuGet package.

Without any code change, this package is able to initialize the Sentry SDK and capture events while including additional properties like `Exception` data and more.


## Installation

Using package manager:

```powershell
Install-Package Sentry.Log4Net
```

Or using the .NET Core CLI:

```sh
dotnet add Sentry.Log4Net
```

This package extends `Sentry` main SDK. That means besides the log4net `Appender`, through this package you'll also get access to all API and features available in the main `Sentry` SDK.

## Configuration

Once the log4net integration package is installed in your project, you can modify your configuration file to add the appender.
This can be done, for example, via the `app.config` for console and desktop apps or `web.config` in case of ASP.NET.

```xml
<appender name="SentryAppender" type="Sentry.Log4Net.SentryAppender, Sentry.Log4Net">
<Dsn value="___PUBLIC_KEY___"/>
<!--Sends the log event Identity value as the user-->
<SendIdentity value="true" />
<threshold value="INFO" />
</appender>
```

#### SendIdentity

In the example above, the `SendIdentity` flag was switched on. The SDK then will take the log4net `Identity` value and report to Sentry as the user's id.

#### Dsn

Also in the example above, you can find the [DSN](https://docs.sentry.io/quickstart/#configure-the-dsn) being set. That will instruct the `SentryAppender` to initialize the SDK.

> NOTE:
This is only one of the ways to initialize the SDK. If you wish to configure the SDK programatically, you could **leave the DSN out** from the appender configuration section. The SDK needs to be initialized only **once** and since other integrations (like ASP.NET) are also able to initialize the SDK, you only need to pass the DSN to one of these integrations.


### Sample

For a [sample app.config](https://github.com/getsentry/sentry-dotnet/blob/master/samples/Sentry.Samples.Log4Net/app.config) or a complete working [sample](https://github.com/getsentry/sentry-dotnet/tree/master/samples/Sentry.Samples.Log4Net) to see it in action.

![Sample event in Sentry](https://github.com/getsentry/sentry-dotnet/blob/master/samples/Sentry.Samples.Log4Net/.assets/log4net-sample.gif?raw=true)
Loading