Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ sidebar_section: features
notSupported:
- dotnet.google-cloud-functions
- dotnet.log4net
- dotnet.nlog
- dotnet.xamarin
---

Expand Down
5 changes: 4 additions & 1 deletion docs/platforms/dotnet/guides/nlog/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Sentry provides an integration with `NLog` through the [Sentry.NLog NuGet packag
## 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 `Error` call will create an `Event` which will include all log messages of level `Info`, `Warn` 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
6 changes: 6 additions & 0 deletions docs/product/logs/getting-started/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@ To set up Sentry Logs, use the links below for supported SDKs. After it's been s
url="/platforms/dotnet/guides/serilog/logs/"
skill="sentry-dotnet-sdk"
/>
- <LinkWithPlatformIcon
platform="dotnet.nlog"
label="NLog"
url="/platforms/dotnet/guides/nlog/logs/"
skill="sentry-dotnet-sdk"
/>

### Native

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 @@ -4,6 +4,7 @@ Available integrations:
<IntegrationListItem href="/platforms/dotnet/guides/maui/logs/">.NET Multi-platform App UI (.NET MAUI)</IntegrationListItem>
<IntegrationListItem href="/platforms/dotnet/guides/extensions-logging/logs/">Microsoft.Extensions.Logging</IntegrationListItem>
<IntegrationListItem href="/platforms/dotnet/guides/serilog/logs/">Serilog</IntegrationListItem>
<IntegrationListItem href="/platforms/dotnet/guides/nlog/logs/">NLog</IntegrationListItem>
</ul>

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).
6 changes: 5 additions & 1 deletion platform-includes/logs/options/dotnet.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#### EnableLogs

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

Expand All @@ -12,6 +12,10 @@ Set to `true` in order to enable the logging integration via the `ILogger<TCateg
Set to `true` in order to enable the logging integration via the `Log`/`Logger` APIs.
</PlatformSection>

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

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

#### Configure Microsoft.Extensions.Logging Filters
Expand Down
6 changes: 5 additions & 1 deletion platform-includes/logs/requirements/dotnet.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<PlatformSection notSupported={["dotnet.serilog"]}>
<PlatformSection notSupported={["dotnet.serilog", "dotnet.nlog"]}>
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.16.0` and above.
</PlatformSection>

<PlatformSection supported={["dotnet.nlog"]}>
Logs for <PlatformOrGuideName/> are supported in Sentry <PlatformOrGuideName/> SDK version `6.8.0` and above.
</PlatformSection>
19 changes: 18 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 `EnableLogs` option set to `true`.

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

```csharp
SentrySdk.Init(options =>
Expand Down Expand Up @@ -70,6 +70,23 @@ This enables the `SentrySdk.Logger` APIs, as well as the `Microsoft.Extensions.L
```


</PlatformSection>

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

```csharp
LogManager.Configuration = new LoggingConfiguration();
LogManager.Configuration
.AddSentry(options =>
{
options.Dsn = "___PUBLIC_DSN___";
// Enable logs to be sent to Sentry
options.EnableLogs = true;
});
```

If the SDK is initialized elsewhere (for example, through ASP.NET Core), enable `EnableLogs` on those options instead. The NLog target then captures logs without initializing the SDK itself.

</PlatformSection>

It does _not_ capture the `Console.WriteLine()` standard output stream.
Expand Down
33 changes: 31 additions & 2 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", "dotnet.serilog"]}>
<PlatformSection notSupported={["dotnet.aspnetcore", "dotnet.azure-functions-worker", "dotnet.blazor-webassembly", "dotnet.extensions-logging", "dotnet.maui", "dotnet.serilog", "dotnet.nlog"]}>

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

Expand Down Expand Up @@ -81,7 +81,36 @@ The _Enrichments_ of _log events_ are attached as attributes to the logs, alongs

</PlatformSection>

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

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

The `Logger` type exposes various methods that you can use to log messages at six different log levels automatically mapped to Sentry's severity:

| NLog.LogLevel | Sentry.SentryLogLevel | Sentry Logs UI Severity |
| --- | --- | --- |
| Trace | Trace | trace |
| Debug | Debug | debug |
| Info | Info | info |
| Warn | 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
var logger = LogManager.GetCurrentClassLogger();

logger.Info("A simple log message");
logger.Error("A {Parameter} log message", "formatted");
logger.WithProperty("Property", "Value").Warn("Message with Property");
```

The _properties_ of _log events_ are attached as attributes to the logs, alongside a set of default attributes automatically provided by the SDK. The logger name is attached as the `category.name` attribute.

</PlatformSection>

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

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