---
title: "Logs"
description: "Structured logs allow you to send, view and query logs sent from your applications within Sentry."
url: https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs/
---

# Set Up Logs | Sentry for Azure Functions

With Sentry Structured Logs, you can send text-based log information from your applications to Sentry. Once in Sentry, these logs can be viewed alongside relevant errors, searched by text-string, or searched using their individual attributes.

## [Requirements](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#requirements)

Logs for <!-- -->Azure Functions <!-- -->are supported in Sentry <!-- -->Azure Functions <!-- -->SDK version `5.14.0` and above.

## [Setup](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#setup)

To enable logging, you need to initialize the SDK with the `EnableLogs` option set to `true`.

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

## [Usage](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#usage)

Once the feature is enabled on the SDK and the SDK is initialized, you can send logs using instances of the [ILogger](https://learn.microsoft.com/dotnet/api/microsoft.extensions.logging.ilogger-1) interface, resolved through *.NET dependency injection*.

The `LoggerExtensions` extension methods expose various overloads that you can use to log messages at six different log levels automatically mapped to Sentry's severity:

| 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                   |

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
public sealed class MyService(ILogger<MyService> logger)
{
    public void Invoke()
    {
        logger.LogInformation("A simple log message");
        logger.LogError("A {Parameter} log message", "formatted");
        logger.LogWarning(new EventId(1, nameof(Invoke)), "Message with EventId");
    }
}
```

The `ILogger`'s *CategoryName*, as well as the `EventId` (if provided), are attached as attributes to the logs.

For more information, see the article on [Logging in C# and .NET](https://learn.microsoft.com//dotnet/core/extensions/logging). Sentry Structured Logs also work with [High-performance logging in .NET](https://learn.microsoft.com/dotnet/core/extensions/high-performance-logging) and [Compile-time logging source generation](https://learn.microsoft.com/dotnet/core/extensions/logger-message-generator) alike.

## [Options](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#options)

#### [EnableLogs](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#enablelogs)

Set to `true` in order to enable the logging integration via the `ILogger<TCategoryName>` API.

#### [SetBeforeSendLog](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#setbeforesendlog)

To filter logs, or update them before they are sent to Sentry, you can use the `SetBeforeSendLog(Func<SentryLog, SentryLog?>)` option.

```csharp
options =>
{
    options.Dsn = "___PUBLIC_DSN___";
    options.EnableLogs = true;
    // a callback that is invoked before sending a log to Sentry
    options.SetBeforeSendLog(static log =>
    {
        // filter out all info logs
        if (log.Level is SentryLogLevel.Info)
        {
            return null;
        }

        // filter out logs based on some attribute they have
        if (log.TryGetAttribute("suppress", out var attribute) && attribute is true)
        {
            return null;
        }

        // set a custom attribute for all other logs sent to Sentry
        log.SetAttribute("my.attribute", "value");

        return log;
    });
});
```

The `beforeSendLog` delegate receives a log object, and should return the log object if you want it to be sent to Sentry, or `null` if you want to discard it.

The log object of type `SentryLog` has the following members:

| Member                                          | Type                                           | Description                                                                                                                                                                         |
| ----------------------------------------------- | ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Timestamp`                                     | `DateTimeOffset`                               | The timestamp of the log.                                                                                                                                                           |
| `TraceId`                                       | `SentryId`                                     | The trace id of the log.                                                                                                                                                            |
| `Level`                                         | `SentryLogLevel`                               | The severity level of the log. Either `Trace`, `Debug`, `Info`, `Warning`, `Error`, or `Fatal`.                                                                                     |
| `Message`                                       | `string`                                       | The formatted log message.                                                                                                                                                          |
| `Template`                                      | `string?`                                      | The parameterized template string.                                                                                                                                                  |
| `Parameters`                                    | `ImmutableArray<KeyValuePair<string, object>>` | The parameters to the template string.                                                                                                                                              |
| `SpanId`                                        | `SpanId?`                                      | The span id of the span that was active when the log was collected.                                                                                                                 |
| `TryGetAttribute(string key, out object value)` | Method                                         | Gets the attribute value associated with the specified key. Returns `true` if the log contains an attribute with the specified key and it's value is not `null`, otherwise `false`. |
| `SetAttribute(string key, object value)`        | Method                                         | Sets a key-value pair of data attached to the log. Supported types are `string`, `bool`, integers up to a size of 64-bit signed, and floating-point numbers up to a size of 64-bit. |

## [Default Attributes](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#default-attributes)

The .NET SDK automatically sets several default attributes on all log entries to provide context and improve debugging:

### [Core Attributes](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#core-attributes)

* `environment`: The environment set in the SDK if defined. This is sent from the SDK as `sentry.environment`.
* `release`: The release set in the SDK if defined. This is sent from the SDK as `sentry.release`.
* `sdk.name`: The name of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.name`.
* `sdk.version`: The version of the SDK that sent the log. This is sent from the SDK as `sentry.sdk.version`.

### [Message Template Attributes](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#message-template-attributes)

If the log was parameterized, Sentry adds the message template and parameters as log attributes.

* `message.template`: The parameterized template string. This is sent from the SDK as `sentry.message.template`.
* `message.parameter.X`: The parameters to fill the template string. X can either be the number that represent the parameter's position in the template string (`sentry.message.parameter.0`, `sentry.message.parameter.1`, etc) or the parameter's name (`sentry.message.parameter.item_id`, `sentry.message.parameter.user_id`, etc). This is sent from the SDK as `sentry.message.parameter.X`.

### [Server Attributes](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#server-attributes)

* `server.address`: The address of the server that sent the log. Equivalent to `server_name` that gets attached to Sentry errors.

### [User Attributes](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#user-attributes)

If user information is available in the current scope, the following attributes are added to the log:

* `user.id`: The user ID.
* `user.name`: The username.
* `user.email`: The email address.

### [Integration Attributes](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#integration-attributes)

If a log is generated by an SDK integration, the SDK will set additional attributes to help you identify the source of the log.

* `origin`: The origin of the log. This is sent from the SDK as `sentry.origin`.

## [Other Logging Integrations](https://docs.sentry.io/platforms/dotnet/guides/azure-functions-worker/logs.md#other-logging-integrations)

Available integrations:

* [ASP.NET Core](https://docs.sentry.io/platforms/dotnet/guides/aspnetcore/logs.md)
* [.NET Multi-platform App UI (.NET MAUI)](https://docs.sentry.io/platforms/dotnet/guides/maui/logs.md)
* [Microsoft.Extensions.Logging](https://docs.sentry.io/platforms/dotnet/guides/extensions-logging/logs.md)
* [Serilog](https://docs.sentry.io/platforms/dotnet/guides/serilog/logs.md)

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).
