Azure.Monitor.Ingestion 1.0.0-beta.4

Prefix Reserved
This is a prerelease version of Azure.Monitor.Ingestion.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Azure.Monitor.Ingestion --version 1.0.0-beta.4                
NuGet\Install-Package Azure.Monitor.Ingestion -Version 1.0.0-beta.4                
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="Azure.Monitor.Ingestion" Version="1.0.0-beta.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Azure.Monitor.Ingestion --version 1.0.0-beta.4                
#r "nuget: Azure.Monitor.Ingestion, 1.0.0-beta.4"                
#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.
// Install Azure.Monitor.Ingestion as a Cake Addin
#addin nuget:?package=Azure.Monitor.Ingestion&version=1.0.0-beta.4&prerelease

// Install Azure.Monitor.Ingestion as a Cake Tool
#tool nuget:?package=Azure.Monitor.Ingestion&version=1.0.0-beta.4&prerelease                

Azure Monitor Ingestion client library for .NET

The Azure Monitor Ingestion client library is used to send custom logs to Azure Monitor.

This library allows you to send data from virtually any source to supported built-in tables or to custom tables that you create in Log Analytics workspace. You can even extend the schema of built-in tables with custom columns.

Resources:

Getting started

Prerequisites

Install the package

Install the Azure Monitor Ingestion client library for .NET with NuGet:

dotnet add package Azure.Monitor.Ingestion --prerelease

Authenticate the client

An authenticated client is required to ingest data. To authenticate, create an instance of a TokenCredential class. Pass it to the constructor of the LogsIngestionClient class.

To authenticate, the following example uses DefaultAzureCredential from the Azure.Identity package:

var endpoint = new Uri("<data_collection_endpoint_uri>");
var credential = new DefaultAzureCredential();
var client = new LogsIngestionClient(endpoint, credential);

Upload the logs

For examples of logs ingestion, see the Examples section.

Key concepts

Data collection endpoint

Data collection endpoints (DCEs) allow you to uniquely configure ingestion settings for Azure Monitor. This article provides an overview of DCEs, including their contents, structure, and how you can create and work with them.

Data collection rule

Data collection rules (DCRs) define data collected by Azure Monitor and specify how and where that data should be sent or stored. The REST API call must specify a DCR to use. A single DCE can support multiple DCRs, so you can specify a different DCR for different sources and target tables.

The DCR must understand the structure of the input data and the structure of the target table. If the two don't match, it can use a transformation to convert the source data to match the target table. You may also use the transform to filter source data and perform any other calculations or conversions.

For more information, see Data collection rules in Azure Monitor.

Log Analytics workspace tables

Custom logs can send data to any custom table that you create and to certain built-in tables in your Log Analytics workspace. The target table must exist before you can send data to it. The following built-in tables are currently supported:

Thread safety

We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This design ensures that the recommendation of reusing client instances is always safe, even across threads.

Additional concepts

Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime

Examples

You can familiarize yourself with different APIs using samples.

Upload custom logs

You can upload logs using either the LogsIngestionClient.Upload or the LogsIngestionClient.UploadAsync method. Note the data ingestion limits.

var endpoint = new Uri("<data_collection_endpoint>");
var ruleId = "<data_collection_rule_id>";
var streamName = "<stream_name>";

var credential = new DefaultAzureCredential();
LogsIngestionClient client = new(endpoint, credential);
DateTimeOffset currentTime = DateTimeOffset.UtcNow;

// Use BinaryData to serialize instances of an anonymous type into JSON
BinaryData data = BinaryData.FromObjectAsJson(
    new[] {
        new
        {
            Time = currentTime,
            Computer = "Computer1",
            AdditionalContext = new
            {
                InstanceName = "user1",
                TimeZone = "Pacific Time",
                Level = 4,
                CounterName = "AppMetric1",
                CounterValue = 15.3
            }
        },
        new
        {
            Time = currentTime,
            Computer = "Computer2",
            AdditionalContext = new
            {
                InstanceName = "user2",
                TimeZone = "Central Time",
                Level = 3,
                CounterName = "AppMetric1",
                CounterValue = 23.5
            }
        },
    });

// Upload our logs
Response response = await client.UploadAsync(
    ruleId,
    streamName,
    RequestContent.Create(data)).ConfigureAwait(false);

Verify logs

You can verify that your data has been uploaded correctly by using the Azure Monitor Query library. Run the Upload custom logs sample first before verifying the logs.

var workspaceId = "<log_analytics_workspace_id>";
var tableName = "<table_name>";

var credential = new DefaultAzureCredential();
LogsQueryClient logsQueryClient = new(credential);

LogsBatchQuery batch = new();
string query = tableName + " | Count;";
string countQueryId = batch.AddWorkspaceQuery(
    workspaceId,
    query,
    new QueryTimeRange(TimeSpan.FromDays(1)));

Response<LogsBatchQueryResultCollection> queryResponse =
    await logsQueryClient.QueryBatchAsync(batch).ConfigureAwait(false);

Console.WriteLine("Table entry count: " +
    queryResponse.Value.GetResult<int>(countQueryId).Single());

Troubleshooting

Enabling logging

The Azure SDK for .NET offers a consistent logging story to aid in troubleshooting application errors and expedite their resolution. The logs produced will capture the application's flow before reaching the terminal state to help locate the root issue. For information on enabling logging, see Logging with the Azure SDK for .NET.

Next steps

To learn more about Azure Monitor, see the Azure Monitor service documentation.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately. For example, labels and comments. Follow the instructions provided by the bot. You'll only need to sign the CLA once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any questions or comments.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Azure.Monitor.Ingestion:

Package Downloads
CB.Serilog.Sinks.AzureLogAnalytics

A Serilog Sink for Azure Log Analytics that used the Log Ingestion API

Adora.Shared

Adora shared library

RzWork.AzureMonitor.TraceListener

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.2 125,683 4/3/2024
1.1.1 147,412 10/17/2023
1.1.0 3,742 10/9/2023
1.1.0-beta.1 744 10/9/2023
1.0.0 62,735 2/21/2023
1.0.0-beta.4 16,735 10/11/2022
1.0.0-beta.3 468 9/23/2022
1.0.0-beta.2 223 9/1/2022
1.0.0-beta.1 290 7/7/2022