MAUI Integration
ByteHide Logger provides comprehensive integration with .NET MAUI applications, automatically capturing navigation events, app lifecycle, device information, and unhandled exceptions.
Installation
Install the MAUI integration package:
dotnet add package Bytehide.Logger.Maui
Supported Versions
- .NET 6, .NET 7, .NET 8, .NET 9
Basic Configuration
Configure ByteHide Logger in your MauiProgram.cs
:
using Bytehide.Logger.Maui.Extensions;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.UseMauiApp<App>();
// Add ByteHide Logger
builder.Services.AddBytehideLogging(options => {
options.ProjectToken = "your-project-token";
});
var app = builder.Build();
// Initialize the logger
app.Services.UseBytehideLogging();
return app;
}
}
Configuration Options
Basic Options
builder.Services.AddBytehideLogging(options => {
// Required
options.ProjectToken = "your-project-token";
// Event Tracking
options.CaptureNavigationEvents = true; // Log page navigation
options.CaptureLifecycleEvents = true; // Log app lifecycle
options.CaptureUnhandledExceptions = true; // Log crashes
// Device Information
options.LogDeviceInfo = true; // Log device metadata
options.IdentifyDeviceAutomatically = true; // Add device ID to logs
// Performance Features
options.UseCompactLogs = true; // Shorter log messages
options.SlowNavigationThresholdMs = 500; // Flag slow navigation
options.SlowAppStartupThresholdMs = 2000; // Flag slow startup
options.TrackMemoryUsage = true; // Monitor memory usage
// Integration
options.ReplaceDefaultLogger = true; // Use as ILogger provider
options.LogLevel = LogLevel.Info; // Minimum log level
});
Advanced Options
builder.Services.AddBytehideLogging(options => {
options.ProjectToken = "your-project-token";
// Filtering
options.ExcludedPageTypes = new[] { // Skip certain page types
"LoadingPage", "SplashPage"
};
// Performance Monitoring
options.NavigationDuplicateSuppressionSeconds = 5; // Avoid duplicates
});
Features
Automatic Navigation Tracking
// Automatically logs when users navigate between pages:
// [INFO] Navigation from MainPage to ProductPage completed in 245ms
App Lifecycle Monitoring
// Automatically logs app lifecycle events:
// [INFO] App started in 1.2 seconds
// [INFO] App entering background
// [INFO] App resuming from background
Device Information
// Automatically captures:
// - Device model and manufacturer
// - Operating system version
// - Screen dimensions
// - Available memory
// - App version
Memory Usage Tracking
// When enabled, logs memory usage at key events:
// [INFO] App startup completed - Memory: 45MB
// [WARN] Navigation completed - Memory: 120MB (High usage detected)
Custom Logging
public partial class ProductPage : ContentPage
{
public ProductPage()
{
InitializeComponent();
Log.WithTags("maui", "product-page")
.WithMetadata("pageId", "ProductPage")
.Info("Product page initialized");
}
private async void OnSearchClicked(object sender, EventArgs e)
{
try
{
Log.WithTags("search", "user-action")
.WithMetadata("query", searchEntry.Text)
.Info("User performed search");
var results = await SearchAsync(searchEntry.Text);
Log.WithMetadata("resultCount", results.Count)
.Info("Search completed");
}
catch (Exception ex)
{
Log.Error("Search failed", ex);
}
}
}
File Logging
builder.Services.AddBytehideLogging(
options => {
options.ProjectToken = "your-project-token";
},
logSettings => {
// Enable file logging
logSettings.Persist = true;
logSettings.FilePath = "logs/maui-app.log";
logSettings.RollingInterval = RollingInterval.Day;
logSettings.FileSizeLimitBytes = 10 * 1024 * 1024; // 10MB
}
);
Platform-Specific Features
Android
- Application lifecycle events
- Memory pressure warnings
- Activity transitions
iOS
- App background/foreground transitions
- Memory warnings
- View controller navigation
Windows
- Window lifecycle events
- System memory monitoring
Performance Monitoring
Slow Navigation Detection
// Configure thresholds
builder.Services.AddBytehideLogging(options => {
options.ProjectToken = "your-project-token";
options.SlowNavigationThresholdMs = 500;
});
// Slow navigation will be logged as warnings:
// [WARN] Slow navigation detected: MainPage to DetailsPage took 782ms
Memory Monitoring
// Enable memory tracking
builder.Services.AddBytehideLogging(options => {
options.ProjectToken = "your-project-token";
options.TrackMemoryUsage = true;
});
// Memory usage logged at key events:
// [INFO] App resumed - Memory usage: 67MB
// [WARN] Navigation completed - High memory usage: 145MB
Crash Reporting
// Unhandled exceptions are automatically captured:
// [CRITICAL] Unhandled exception in MAUI app
// Exception: NullReferenceException at ProductPage.LoadData()
// Device: iPhone 14 Pro, iOS 16.5
// Memory: 89MB, Available: 2.1GB
Options Reference
Option | Type | Default | Description |
---|---|---|---|
ProjectToken | string | null | Your ByteHide project token |
CaptureNavigationEvents | bool | true | Log page navigation events |
CaptureLifecycleEvents | bool | true | Log app lifecycle events |
CaptureUnhandledExceptions | bool | true | Log unhandled exceptions |
LogDeviceInfo | bool | true | Include device information |
UseCompactLogs | bool | false | Use shorter log format |
SlowNavigationThresholdMs | int | 500 | Threshold for slow navigation warnings |
SlowAppStartupThresholdMs | int | 2000 | Threshold for slow startup warnings |
TrackMemoryUsage | bool | false | Monitor memory usage |
ExcludedPageTypes | string[] | [] | Page types to exclude from navigation logging |
IdentifyDeviceAutomatically | bool | false | Add device ID to all logs |
NavigationDuplicateSuppressionSeconds | int? | null | Suppress duplicate navigation logs |
ReplaceDefaultLogger | bool | false | Use as ILogger provider |
LogLevel | LogLevel | Warn | Minimum log level |
Best Practices
- Enable
UseCompactLogs
in production to reduce log volume - Use
TrackMemoryUsage
during development to identify memory leaks - Configure
ExcludedPageTypes
to skip unimportant pages - Test file logging permissions on target platforms
- Adjust thresholds based on your app's performance characteristics
Initialization Order
Ensure proper initialization order:
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
// 1. Configure MAUI
builder.UseMauiApp<App>();
// 2. Add ByteHide services
builder.Services.AddBytehideLogging(options => { /* ... */ });
// 3. Build app
var app = builder.Build();
// 4. Initialize logger (important!)
app.Services.UseBytehideLogging();
return app;
}
Next Steps
- Configuration - Set up your project token
- Exception Handling - Mobile crash reporting
- Global Properties - Add device context to all logs