Skip to content
Open
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
1 change: 0 additions & 1 deletion docs/platforms/dotnet/common/logs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ notSupported:
- dotnet.google-cloud-functions
- dotnet.log4net
- dotnet.nlog
- dotnet.serilog
- dotnet.xamarin
---

Expand Down
5 changes: 4 additions & 1 deletion docs/platforms/dotnet/guides/serilog/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Sentry provides an integration with `Serilog` through the [Sentry.Serilog NuGet
## Overview of the features

- Store log messages as breadcrumbs
- Send events to sentry
- Send events to Sentry
- Send structured logs to Sentry

Two separate settings define the minimum log level to keep the log entry as a `Breadcrumb` and to send an `Event` to Sentry. The events include any stored breadcrumb on that [scope](enriching-events/scopes/).

Expand All @@ -19,6 +20,8 @@ The default value to report a log entry as an event to Sentry is `Error`.

This means that out of the box, any `LogError` call will create an `Event` which will include all log messages of level `Information`, `Warning` and also `Error` and `Critical`.

Additionally, when enabled, log messages are sent to Sentry as [Structured Logs](logs/).

## Install

Add the Sentry dependency:
Expand Down
5 changes: 5 additions & 0 deletions docs/product/explore/logs/getting-started/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s
label="Microsoft.Extensions.Logging"
url="/platforms/dotnet/guides/extensions-logging/logs/"
/>
- <LinkWithPlatformIcon
platform="dotnet.serilog"
label="Serilog"
url="/platforms/dotnet/guides/serilog/logs/"
/>

## Upcoming SDKs

Expand Down
1 change: 1 addition & 0 deletions platform-includes/logs/integrations/dotnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ Available integrations:
- [ASP.NET Core](/platforms/dotnet/guides/aspnetcore/logs/)
- [.NET Multi-platform App UI (.NET MAUI)](/platforms/dotnet/guides/maui/logs/)
- [Microsoft.Extensions.Logging](/platforms/dotnet/guides/extensions-logging/logs/)
- [Serilog](/platforms/dotnet/guides/serilog/logs/)

If there's an integration you would like to see, open a [new issue on GitHub](https://github.com/getsentry/sentry-dotnet/issues/new/choose).
12 changes: 11 additions & 1 deletion platform-includes/logs/options/dotnet.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#### Experimental.EnableLogs

Set to `true` in order to enable the `SentrySdk.Experimental.Logger` APIs, as well as logging integrations via the `ILogger<TCategoryName>` API.
<PlatformSection notSupported={["dotnet.aspnetcore", "dotnet.azure-functions-worker", "dotnet.blazor-webassembly", "dotnet.extensions-logging", "dotnet.maui", "dotnet.serilog"]}>
Set to `true` in order to enable the `SentrySdk.Experimental.Logger` APIs.
</PlatformSection>

<PlatformSection supported={["dotnet.aspnetcore", "dotnet.azure-functions-worker", "dotnet.blazor-webassembly", "dotnet.extensions-logging", "dotnet.maui"]}>
Set to `true` in order to enable the logging integration via the `ILogger<TCategoryName>` API.
</PlatformSection>

<PlatformSection supported={["dotnet.serilog"]}>
Set to `true` in order to enable the logging integration via the `Log`/`Logger` APIs.
</PlatformSection>

#### Experimental.SetBeforeSendLog

Expand Down
8 changes: 7 additions & 1 deletion platform-includes/logs/requirements/dotnet.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
Logs for .NET are supported in Sentry .NET SDK version `5.14.0` and above.
<PlatformSection notSupported={["dotnet.serilog"]}>
Logs for <PlatformOrGuideName/> are supported in Sentry <PlatformOrGuideName/> SDK version `5.14.0` and above.
</PlatformSection>

<PlatformSection supported={["dotnet.serilog"]}>
Logs for <PlatformOrGuideName/> are supported in Sentry <PlatformOrGuideName/> SDK version `5.15.0` and above.
</PlatformSection>
15 changes: 14 additions & 1 deletion platform-includes/logs/setup/dotnet.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
To enable logging, you need to initialize the SDK with the `Experimental.EnableLogs` option set to `true`.

<PlatformSection notSupported={["dotnet.aspnetcore", "dotnet.aws-lambda", "dotnet.azure-functions-worker", "dotnet.blazor-webassembly", "dotnet.extensions-logging", "dotnet.maui"]}>
<PlatformSection notSupported={["dotnet.aspnetcore", "dotnet.aws-lambda", "dotnet.azure-functions-worker", "dotnet.blazor-webassembly", "dotnet.extensions-logging", "dotnet.maui", "dotnet.serilog"]}>

```csharp
SentrySdk.Init(options =>
Expand Down Expand Up @@ -53,3 +53,16 @@ SentrySdk.Init(options =>
```

</PlatformSection>

<PlatformSection supported={["dotnet.serilog"]}>

```csharp
.WriteTo.Sentry(options =>
{
options.Dsn = "___PUBLIC_DSN___";
// Enable logs to be sent to Sentry
options.Experimental.EnableLogs = true;
});
```

</PlatformSection>
56 changes: 41 additions & 15 deletions platform-includes/logs/usage/dotnet.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<PlatformSection notSupported={["dotnet.aspnetcore", "dotnet.azure-functions-worker", "dotnet.blazor-webassembly", "dotnet.extensions-logging", "dotnet.maui"]}>
<PlatformSection notSupported={["dotnet.aspnetcore", "dotnet.azure-functions-worker", "dotnet.blazor-webassembly", "dotnet.extensions-logging", "dotnet.maui", "dotnet.serilog"]}>

Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `SentrySdk.Experimental.Logger` APIs.

Expand All @@ -8,7 +8,7 @@ These properties will be sent to Sentry, and can be searched from within the Log

```csharp
SentrySdk.Experimental.Logger.LogInfo("A simple log message");
SentrySdk.Experimental.Logger.LogError("A {0} log message", ["formatted"]);
SentrySdk.Experimental.Logger.LogError("A {0} log message", "formatted");
```

<Alert title="Note">
Expand All @@ -27,12 +27,12 @@ The `LoggerExtensions` extension methods expose various overloads that you can u

| Microsoft.Extensions.Logging.LogLevel | Sentry.SentryLogLevel | Sentry Logs UI Severity |
| --- | --- | --- |
| Trace | Trace | TRACE |
| Debug | Debug | DEBUG |
| Information | Info | INFO |
| Warning | Warning | WARN |
| Error | Error | ERROR |
| Critical | Fatal | FATAL |
| Trace | Trace | trace |
| Debug | Debug | debug |
| Information | Info | info |
| Warning | Warning | warn |
| Error | Error | error |
| Critical | Fatal | fatal |

These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column.

Expand All @@ -55,22 +55,48 @@ Sentry Structured Logs also work with [High-performance logging in .NET](https:/

</PlatformSection>

<PlatformSection notSupported={["dotnet.aspnetcore", "dotnet.azure-functions-worker", "dotnet.blazor-webassembly", "dotnet.extensions-logging", "dotnet.maui"]}>
<PlatformSection supported={["dotnet.serilog"]}>

Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the _Serilog_ APIs.

The static `Log` and instance `Logger` types expose various methods that you can use to log messages at six different log levels automatically mapped to Sentry's severity:

| Serilog.Events.LogEventLevel | Sentry.SentryLogLevel | Sentry Logs UI Severity |
| --- | --- | --- |
| Verbose | Trace | trace |
| Debug | Debug | debug |
| Information | Info | info |
| Warning | Warning | warn |
| Error | Error | error |
| Fatal | Fatal | fatal |

These properties will be sent to Sentry, and can be searched from within the Logs UI, and even added to the Logs views as a dedicated column.

```csharp
using (LogContext.PushProperty("Version", 5150))
{
Log.Information("A simple log message");
Log.Error("A {Parameter} log message", "formatted");
Log.ForContext("Property", "Value").Warning("Message with Property");
}
```

The _Enrichments_ of _log events_ are attached as attributes to the logs, alongside a set of default attributes automatically provided by the SDK.

</PlatformSection>

<PlatformSection notSupported={["dotnet.aspnetcore", "dotnet.azure-functions-worker", "dotnet.blazor-webassembly", "dotnet.extensions-logging", "dotnet.maui", "dotnet.serilog"]}>

The SDK automatically provides a set of default attributes attached to your logs.
Additionally, you can attach custom attributes via a delegate.

```csharp
SentrySdk.Experimental.Logger.LogWarning("A log message with additional attributes.", [], static log =>
SentrySdk.Experimental.Logger.LogWarning(static log =>
{
log.SetAttribute("my.attribute", "value");
});
}, "A log message with additional attributes.");
```

<Alert title="Note">
Please note that we will revise the API shape to set custom attributes during the experimental phase of the feature.
</Alert>

Supported attribute types are:
- Textual: `string` and `char`
- Logical: `bool`
Expand Down