diff --git a/docs/platforms/dotnet/common/logs/index.mdx b/docs/platforms/dotnet/common/logs/index.mdx index 6482e81370dc9d..63fd1a0541f7e3 100644 --- a/docs/platforms/dotnet/common/logs/index.mdx +++ b/docs/platforms/dotnet/common/logs/index.mdx @@ -6,7 +6,6 @@ sidebar_order: 2 sidebar_section: features notSupported: - dotnet.google-cloud-functions - - dotnet.log4net - dotnet.nlog - dotnet.xamarin --- diff --git a/docs/platforms/dotnet/guides/log4net/index.mdx b/docs/platforms/dotnet/guides/log4net/index.mdx index 1c239fea255b01..c2b7861e62f4ad 100644 --- a/docs/platforms/dotnet/guides/log4net/index.mdx +++ b/docs/platforms/dotnet/guides/log4net/index.mdx @@ -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: diff --git a/docs/product/logs/getting-started/index.mdx b/docs/product/logs/getting-started/index.mdx index 10d82fbc7a1fd8..13c80f4ea18366 100644 --- a/docs/product/logs/getting-started/index.mdx +++ b/docs/product/logs/getting-started/index.mdx @@ -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" /> +- ### Native diff --git a/platform-includes/logs/integrations/dotnet.mdx b/platform-includes/logs/integrations/dotnet.mdx index cbc91c391bed56..a62f5416e464a9 100644 --- a/platform-includes/logs/integrations/dotnet.mdx +++ b/platform-includes/logs/integrations/dotnet.mdx @@ -4,6 +4,7 @@ Available integrations: .NET Multi-platform App UI (.NET MAUI) Microsoft.Extensions.Logging Serilog +log4net 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). diff --git a/platform-includes/logs/options/dotnet.mdx b/platform-includes/logs/options/dotnet.mdx index 7d20f79800a624..ce8093d0b44600 100644 --- a/platform-includes/logs/options/dotnet.mdx +++ b/platform-includes/logs/options/dotnet.mdx @@ -1,6 +1,6 @@ #### EnableLogs - + Set to `true` in order to enable the `SentrySdk.Logger` APIs. @@ -12,6 +12,10 @@ Set to `true` in order to enable the logging integration via the `ILogger + +Set to `true` in order to enable the logging integration via the log4net `ILog` APIs. + + #### Configure Microsoft.Extensions.Logging Filters diff --git a/platform-includes/logs/requirements/dotnet.mdx b/platform-includes/logs/requirements/dotnet.mdx index 3f0941afd2f207..b0c0e77ea0a799 100644 --- a/platform-includes/logs/requirements/dotnet.mdx +++ b/platform-includes/logs/requirements/dotnet.mdx @@ -1,7 +1,11 @@ - + Logs for are supported in Sentry SDK version `5.14.0` and above. Logs for are supported in Sentry SDK version `5.16.0` and above. + + +Logs for are supported in Sentry SDK version `6.8.0` and above. + diff --git a/platform-includes/logs/setup/dotnet.mdx b/platform-includes/logs/setup/dotnet.mdx index d1b49377162331..d82b0998bb6cf4 100644 --- a/platform-includes/logs/setup/dotnet.mdx +++ b/platform-includes/logs/setup/dotnet.mdx @@ -1,6 +1,6 @@ To enable logging, you need to initialize the SDK with the `EnableLogs` option set to `true`. - + ```csharp SentrySdk.Init(options => @@ -70,6 +70,23 @@ This enables the `SentrySdk.Logger` APIs, as well as the `Microsoft.Extensions.L ``` + + + + +`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. + It does _not_ capture the `Console.WriteLine()` standard output stream. diff --git a/platform-includes/logs/usage/dotnet.mdx b/platform-includes/logs/usage/dotnet.mdx index 19ae34be91bcca..6a481c086217a9 100644 --- a/platform-includes/logs/usage/dotnet.mdx +++ b/platform-includes/logs/usage/dotnet.mdx @@ -1,4 +1,4 @@ - + Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `SentrySdk.Logger` APIs. @@ -81,7 +81,42 @@ The _Enrichments_ of _log events_ are attached as attributes to the logs, alongs - + + +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.` 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. + + + + The SDK automatically provides a set of default attributes attached to your logs. Additionally, you can attach custom attributes via a delegate.