Skip to content
Merged
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 @@ -6,7 +6,6 @@ sidebar_order: 2
sidebar_section: features
notSupported:
- dotnet.google-cloud-functions
- dotnet.log4net
- dotnet.nlog
- dotnet.xamarin
---
Expand Down
2 changes: 2 additions & 0 deletions docs/platforms/dotnet/guides/log4net/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Sentry provides an integration with log4net through the [Sentry.Log4Net NuGet pa

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.

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.log4net"
label="log4net"
url="/platforms/dotnet/guides/log4net/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/log4net/logs/">log4net</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.log4net"]}>
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.log4net"]}>
Set to `true` in order to enable the logging integration via the log4net `ILog` 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.log4net"]}>
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.log4net"]}>
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.log4net"]}>

```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.log4net"]}>

`EnableLogs` isn't exposed as a log4net appender setting, so initialize the SDK with `SentrySdk.Init` and leave the DSN out of your log4net appender configuration.

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

The `SentryAppender` configured in your log4net configuration then captures logs without initializing the SDK itself. If the SDK is initialized elsewhere (for example, through ASP.NET Core), enable `EnableLogs` on those options instead.

</PlatformSection>

It does _not_ capture the `Console.WriteLine()` standard output stream.
Expand Down
39 changes: 37 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.log4net"]}>

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,42 @@ 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.log4net"]}>

Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the _log4net_ APIs, for example through the `ILog` methods (`Debug`, `Info`, `Warn`, `Error`, and `Fatal`).

log4net levels are automatically mapped to Sentry's severity:

| log4net.Core.Level | 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
private static readonly ILog Log = LogManager.GetLogger(typeof(Program));

Log.Info("A simple log message");
Log.Error("An error log message");

ThreadContext.Properties["Property"] = "Value";
Log.Warn("Message with a custom property");
```

The log4net _properties_ (from the log event, `ThreadContext`, and `GlobalContext`) are attached as `property.<name>` 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.

The `SentryAppender`'s `Environment` and `SendIdentity` settings also apply to structured logs: when configured, `Environment` sets the log's environment and `SendIdentity` attaches the log4net identity as the user.

Because log4net renders each message before it reaches the appender, structured logs from log4net carry the fully-formatted message but no message template or parameters.

</PlatformSection>

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

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