---
title: .NET MAUI Log Collection
description: Collect logs from your .NET MAUI applications.
breadcrumbs: >-
  Docs > Log Management > Log Collection and Integrations > .NET MAUI Log
  Collection
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# .NET MAUI Log Collection

## Overview{% #overview %}

Send logs to Datadog from your iOS and Android applications built with .NET MAUI using [Datadog's `Datadog.Maui` client-side logging library](https://github.com/DataDog/dd-sdk-maui) and use the following features:

- Log to Datadog in JSON format natively.
- Forward managed C# exceptions.
- Record real client IP addresses and User-Agents.
- Optimize network usage with automatic bulk posts.
- Enrich logs with global attributes, user info, and account info.

## Setup{% #setup %}

1. Before sending logs, initialize the Datadog SDK by following the [.NET MAUI setup documentation](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/maui/setup.md). Make sure `DdSdk.Initialize` (or the `.UseDatadog(...)` builder extension) runs before `DdLogs.Enable()`.

1. Enable the Logs feature.

With the builder extension:

   ```csharp
   using Datadog.Maui;
   using Datadog.Maui.Configuration;
   using Datadog.Maui.Hosting;
   
   public static MauiApp CreateMauiApp()
   {
       var builder = MauiApp.CreateBuilder();
       builder
           .UseMauiApp<App>()
           .UseDatadog(new DdSdkConfiguration
           {
               ClientToken = "<CLIENT_TOKEN>",
               Environment = "<ENV_NAME>",
               TrackingConsent = TrackingConsent.Granted,{% region-param key="maui_site_config" /%}
           })
           .UseDatadogLogs();
   
       return builder.Build();
   }
   ```

Or with the standalone API, call `DdLogs.Enable()` after `DdSdk.Initialize`:

   ```csharp
   using Datadog.Maui;
   
   DdLogs.Enable();
   ```

1. Send a log entry with one of the following methods:

   ```csharp
   DdLogs.Debug("A debug message.");
   DdLogs.Info("Some relevant information?");
   DdLogs.Warn("An important warning...");
   DdLogs.Error("An error was met!");
   ```

Log messages are sent to the Datadog [Log Explorer](https://docs.datadoghq.com/logs/explorer.md) and appear under the service name you configured at SDK initialization.

## Enrich your logs{% #enrich-your-logs %}

Logs inherit context already set on the core SDK. You don't need to attach the same metadata to every call - set it once and every emitted log carries it.

### Global attributes{% #global-attributes %}

Attributes added with `DdSdk.AddAttribute` (or `DdSdk.AddAttributes`) are attached to every log, RUM event, and trace emitted after the call. Use them for cross-cutting context such as feature flags, experiment IDs, or release channels.

```csharp
DdSdk.AddAttribute("plan", "premium");
DdSdk.AddAttribute("experiment", "new-checkout-flow");

// Remove when the context no longer applies
DdSdk.RemoveAttribute("experiment");
```

### User information{% #user-information %}

Use `DdSdk.SetUserInfo` to attach an identity to every log line for the current user. This makes it easier to triage logs that relate to a specific user when investigating a support ticket.

```csharp
DdSdk.SetUserInfo("user-123", "Jane Doe", "jane@example.com",
    new Dictionary<string, object> { { "plan", "premium" } });
```

See [Track user sessions](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/maui/advanced_configuration.md#track-user-sessions) for the full attribute reference.

### Account information{% #account-information %}

For B2B applications, `DdSdk.SetAccountInfo` attaches an account identity to every log. Use it together with — not instead of — user info.

```csharp
DdSdk.SetAccountInfo("acct-456", "Acme Corp",
    new Dictionary<string, object> { { "tier", "enterprise" } });
```

## Custom endpoint{% #custom-endpoint %}

For testing against a local mock server, an on-premises Datadog deployment, or a corporate proxy, pass a `CustomEndpoint` when enabling Logs:

```csharp
DdLogs.Enable(new DdLogsConfiguration
{
    CustomEndpoint = "https://logs-proxy.example.com/v1/input"
});
```

If you also need to route the rest of the SDK traffic through a proxy, configure `ProxyConfiguration` on the SDK itself. See [Advanced Configuration > Proxy configuration](https://docs.datadoghq.com/real_user_monitoring/application_monitoring/maui/advanced_configuration.md#proxy-configuration).

## Batch collection{% #batch-collection %}

All logs are first stored on the local device in batches. Each batch follows the intake specification. Batches are sent as soon as the network is available and the battery is high enough that the Datadog SDK does not impact the end user's experience. If the network is not available while your application is in the foreground, or if an upload of data fails, the batch is kept until it can be sent successfully.

This means that even if users open your application while offline, no data is lost.

The data on disk is automatically discarded if it gets too old. This makes sure the SDK does not use too much disk space.

Before data is uploaded to Datadog, it is stored in cleartext in your application's cache directory.

## Further Reading{% #further-reading %}

- [dd-sdk-maui source code](https://github.com/DataDog/dd-sdk-maui)
- [Learn how to explore your logs](https://docs.datadoghq.com/logs/explorer.md)
