diff --git a/docs/platforms/dotnet/common/logs/index.mdx b/docs/platforms/dotnet/common/logs/index.mdx index b990ffa023da9e..e81f77db013156 100644 --- a/docs/platforms/dotnet/common/logs/index.mdx +++ b/docs/platforms/dotnet/common/logs/index.mdx @@ -7,7 +7,6 @@ notSupported: - dotnet.google-cloud-functions - dotnet.log4net - dotnet.nlog - - dotnet.serilog - dotnet.xamarin --- diff --git a/docs/platforms/dotnet/guides/serilog/index.mdx b/docs/platforms/dotnet/guides/serilog/index.mdx index bb96fcf6236a73..b9fc0ad6c85aa7 100644 --- a/docs/platforms/dotnet/guides/serilog/index.mdx +++ b/docs/platforms/dotnet/guides/serilog/index.mdx @@ -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/). @@ -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: diff --git a/docs/product/explore/logs/getting-started/index.mdx b/docs/product/explore/logs/getting-started/index.mdx index a7517242a69215..522946bee67f1c 100644 --- a/docs/product/explore/logs/getting-started/index.mdx +++ b/docs/product/explore/logs/getting-started/index.mdx @@ -281,6 +281,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/" /> +- ### Native diff --git a/platform-includes/logs/integrations/dotnet.mdx b/platform-includes/logs/integrations/dotnet.mdx index e39212ae4540cf..7dfdde786c31cb 100644 --- a/platform-includes/logs/integrations/dotnet.mdx +++ b/platform-includes/logs/integrations/dotnet.mdx @@ -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). diff --git a/platform-includes/logs/options/dotnet.mdx b/platform-includes/logs/options/dotnet.mdx index 54dc0fb21f41c1..ab726ffe4f38f7 100644 --- a/platform-includes/logs/options/dotnet.mdx +++ b/platform-includes/logs/options/dotnet.mdx @@ -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` API. + +Set to `true` in order to enable the `SentrySdk.Logger` APIs. + + + +Set to `true` in order to enable the logging integration via the `ILogger` API. + + + +Set to `true` in order to enable the logging integration via the `Log`/`Logger` APIs. + #### Experimental.SetBeforeSendLog diff --git a/platform-includes/logs/requirements/dotnet.mdx b/platform-includes/logs/requirements/dotnet.mdx index 0df8ad43b5734f..3f0941afd2f207 100644 --- a/platform-includes/logs/requirements/dotnet.mdx +++ b/platform-includes/logs/requirements/dotnet.mdx @@ -1 +1,7 @@ -Logs for .NET are supported in Sentry .NET SDK version `5.14.0` and above. + +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. + diff --git a/platform-includes/logs/setup/dotnet.mdx b/platform-includes/logs/setup/dotnet.mdx index 9ebb12aaaa7410..29da2b2c311d4a 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 `Experimental.EnableLogs` option set to `true`. - + ```csharp SentrySdk.Init(options => @@ -53,3 +53,16 @@ SentrySdk.Init(options => ``` + + + +```csharp +.WriteTo.Sentry(options => +{ + options.Dsn = "___PUBLIC_DSN___"; + // Enable logs to be sent to Sentry + options.Experimental.EnableLogs = true; +}); +``` + + diff --git a/platform-includes/logs/usage/dotnet.mdx b/platform-includes/logs/usage/dotnet.mdx index a0c85153906938..6eb0bcaf692ec3 100644 --- a/platform-includes/logs/usage/dotnet.mdx +++ b/platform-includes/logs/usage/dotnet.mdx @@ -1,14 +1,14 @@ - + -Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `SentrySdk.Experimental.Logger` APIs. +Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using the `SentrySdk.Logger` APIs. -The `SentrySdk.Experimental.Logger` instance exposes six methods that you can use to log messages at different log levels: `Trace`, `Debug`, `Info`, `Warning`, `Error`, and `Fatal`. +The `SentrySdk.Logger` instance exposes six methods that you can use to log messages at different log levels: `Trace`, `Debug`, `Info`, `Warning`, `Error`, and `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 -SentrySdk.Experimental.Logger.LogInfo("A simple log message"); -SentrySdk.Experimental.Logger.LogError("A {0} log message", ["formatted"]); +SentrySdk.Logger.LogInfo("A simple log message"); +SentrySdk.Logger.LogError("A {0} log message", "formatted"); ``` @@ -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. @@ -55,22 +55,48 @@ Sentry Structured Logs also work with [High-performance logging in .NET](https:/ - + + +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. + + + + 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.Logger.LogWarning(static log => { log.SetAttribute("my.attribute", "value"); -}); +}, "A log message with additional attributes."); ``` - -Please note that we will revise the API shape to set custom attributes during the experimental phase of the feature. - - Supported attribute types are: - Textual: `string` and `char` - Logical: `bool`