Shaunebu.Analytics.AppInsights 1.0.3

dotnet add package Shaunebu.Analytics.AppInsights --version 1.0.3
                    
NuGet\Install-Package Shaunebu.Analytics.AppInsights -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Shaunebu.Analytics.AppInsights" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Shaunebu.Analytics.AppInsights" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Shaunebu.Analytics.AppInsights" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Shaunebu.Analytics.AppInsights --version 1.0.3
                    
#r "nuget: Shaunebu.Analytics.AppInsights, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Shaunebu.Analytics.AppInsights@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Shaunebu.Analytics.AppInsights&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Shaunebu.Analytics.AppInsights&version=1.0.3
                    
Install as a Cake Tool

Shaunebu.Analytics.AppInsights 📗

A lightweight, cross-platform application lifecycle manager for .NET MAUI. This library provides foreground/background lifecycle events across Android, iOS, and Windows, allowing developers to react to app state changes in a consistent way. It abstracts platform differences and exposes a simple event-driven API.

NuGet Version

NET Support NET Support NET Support Support


Features

  • Singleton-based AppInsights telemetry manager for MAUI + .NET Standard.

  • Tracks custom events, page views, and exceptions.

  • Supports offline buffering and batch flushing.

  • Automatically enriches telemetry with platform, OS, app version, session, and user info.

  • Lifecycle-aware: automatically flushes on app resume or sleep.

  • Global default properties for all telemetry.

  • Fully compatible with Microsoft.ApplicationInsights TelemetryClient.

  • Optional debug mode for local logging.


Installation

Install via NuGet:

Install-Package Shaunebu.Analytics.AppInsights

Add namespace references in your project:

using Shaunebu.Analytics.AppInsights;


Initialization

// Initialize AppInsightsManager in App.xaml.cs
AppInsightsManager.Current.Initialize(
    connectionString: "<YOUR-CONNECTION-STRING>",
    debugMode: true,           // Optional: enables debug logging
    batchIntervalSeconds: 30   // Optional: flush interval in seconds
);

Optional: provide a custom TelemetryClient:

var customClient = new TelemetryClient(new TelemetryConfiguration("<YOUR-CONNECTION-STRING>"));
AppInsightsManager.Current.Initialize("<YOUR-CONNECTION-STRING>", customClient: customClient);

Usage

Track Custom Event

AppInsightsManager.Current.TrackEvent(
    "ButtonClicked",
    new Dictionary<string, string>
    {
        { "ButtonName", "Login" }
    },
    metric: 1
);

Track Page View

AppInsightsManager.Current.TrackPageView("MainPage");

Track Exception

try
{
    // Some code that throws
}
catch (Exception ex)
{
    AppInsightsManager.Current.TrackException(ex, new Dictionary<string, string>
    {
        { "Context", "LoginButtonClicked" }
    });
}

Add Global Properties

AppInsightsManager.Current.AddGlobalProperty("AppFlavor", "Beta");

Flush Telemetry Immediately

await AppInsightsManager.Current.FlushAsync();

Properties

Property Type Description
Current AppInsightsManager Singleton instance of the manager.
connectionString string? AppInsights connection string.
Logger IAppLogger? Optional logger for debug/info/error messages.
EnableDebugMode bool Enable or disable debug logging.
SessionId string Current session identifier (auto-generated if not set).
UserId string Current user identifier (persisted via Preferences).

Methods

Method Parameters Description
Initialize(string connectionString, bool debugMode = false, int batchIntervalSeconds = 30, TelemetryClient? customClient = null) instrumentationKey: AppInsights key <br>debugMode: enable debug logging <br>batchIntervalSeconds: flush interval <br>customClient: optional custom TelemetryClient Initializes the telemetry manager and hooks into MAUI lifecycle events.
TrackEvent(string name, Dictionary<string, string>? properties = null, double? metric = null) name: event name <br>properties: optional properties <br>metric: optional numeric value Tracks a custom event.
TrackPageView(string pageName, Dictionary<string, string>? properties = null) pageName: page identifier <br>properties: optional properties Tracks a page view.
TrackException(Exception ex, Dictionary<string, string>? properties = null) ex: Exception object <br>properties: optional properties Tracks an exception.
AddGlobalProperty(string key, string value) key: property name <br>value: property value Adds a property to all future telemetry items.
FlushAsync() None Flushes all buffered telemetry immediately.

Example: Full App.xaml.cs

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        // Initialize AppInsights
        AppInsightsManager.Current.Logger = new ConsoleLogger();
        AppInsightsManager.Current.Initialize("<YOUR-CONNECTION-STRING>", debugMode: true);

        // Track app start
        AppInsightsManager.Current.TrackEvent("App_Started");
    }
}

Logger Interface

Implement your own logger if needed:

public class ConsoleLogger : AppInsightsManager.IAppLogger
{
    public void Info(string message) => Console.WriteLine("[INFO] " + message);
    public void Warn(string message) => Console.WriteLine("[WARN] " + message);
    public void Error(string message, Exception? ex = null)
    {
        Console.WriteLine("[ERROR] " + message + (ex != null ? " " + ex.Message : ""));
    }
}

Lifecycle & Platform Awareness

  • Hooks into Application.Current.Resumed and Application.Current.Slept to automatically flush telemetry.

  • Automatically enriches all telemetry with:

    • Platform (Android/iOS/Windows)

    • OSVersion

    • AppVersion

    • AppBuild

    • SessionId

    • UserId


Notes & Best Practices

  • Enable DebugMode for development to log telemetry locally.

  • AddGlobalProperty for app-wide telemetry metadata.

  • FlushAsync should be called during app shutdown if needed.

  • Works with .NET MAUI and .NET Standard 2.1+ libraries.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Shaunebu.Analytics.AppInsights:

Package Downloads
Shaunebu.Bussiness.ReportGenerator

Enterprise-grade modular reporting SDK for .NET — async, pluggable, and secure. Generate reports (PDF, Excel, Word, HTML, Markdown) with templating, telemetry, and compliance.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 321 10/25/2025
1.0.2 115 10/17/2025
1.0.1 114 10/17/2025