Azure.Monitor.Ingestion
1.0.0-beta.2
Prefix Reserved
See the version list below for details.
dotnet add package Azure.Monitor.Ingestion --version 1.0.0-beta.2
NuGet\Install-Package Azure.Monitor.Ingestion -Version 1.0.0-beta.2
<PackageReference Include="Azure.Monitor.Ingestion" Version="1.0.0-beta.2" />
paket add Azure.Monitor.Ingestion --version 1.0.0-beta.2
#r "nuget: Azure.Monitor.Ingestion, 1.0.0-beta.2"
// Install Azure.Monitor.Ingestion as a Cake Addin #addin nuget:?package=Azure.Monitor.Ingestion&version=1.0.0-beta.2&prerelease // Install Azure.Monitor.Ingestion as a Cake Tool #tool nuget:?package=Azure.Monitor.Ingestion&version=1.0.0-beta.2&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 (see Azure.Identity for DefaultAzureCredential
and other TokenCredential
implementations). Pass it to the constructor of your client class.
To authenticate, the following example uses DefaultAzureCredential
from the Azure.Identity package:
var dataCollectionEndpoint = new Uri("...");
var credential = new DefaultAzureCredential();
var client = new LogsIngestionClient(dataCollectionEndpoint, credential);
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 data collection endpoints including their contents and structure and how you can create and work with them.
Data Collection Rule
Data collection rules (DCR) 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 details, refer to 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 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 create a client and call the client's Upload
method. Take note of the data ingestion limits.
var dataCollectionEndpoint = new Uri("...");
var dataCollectionRuleImmutableId = "...";
var streamName = "...";
TokenCredential credential = new DefaultAzureCredential();
LogsIngestionClient client = new(dataCollectionEndpoint, 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 = client.Upload(dataCollectionRuleImmutableId, streamName, RequestContent.Create(data));
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 = "...";
var tableName = "...";
TokenCredential 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 = logsQueryClient.QueryBatch(batch);
Console.WriteLine("Table entry count: " + queryResponse.Value.GetResult<int>(countQueryId).Single());
Troubleshooting
Enabling logging
Azure SDKs for .Net offer a consistent logging story to help aid in troubleshooting application errors and expedite their resolution. The logs produced will capture the flow of an application before reaching the terminal state to help locate the root issue. View the logging wiki for guidance about enabling logging.
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 (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this 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 additional questions or comments.
Product | Versions 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. |
-
.NETFramework 4.6.1
- Azure.Core (>= 1.25.0)
- System.Text.Json (>= 4.7.2)
-
.NETStandard 2.0
- Azure.Core (>= 1.25.0)
- System.Text.Json (>= 4.7.2)
-
net5.0
- Azure.Core (>= 1.25.0)
- System.Text.Json (>= 4.7.2)
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 | 105,035 | 4/3/2024 |
1.1.1 | 145,021 | 10/17/2023 |
1.1.0 | 3,738 | 10/9/2023 |
1.1.0-beta.1 | 708 | 10/9/2023 |
1.0.0 | 62,037 | 2/21/2023 |
1.0.0-beta.4 | 16,493 | 10/11/2022 |
1.0.0-beta.3 | 466 | 9/23/2022 |
1.0.0-beta.2 | 221 | 9/1/2022 |
1.0.0-beta.1 | 288 | 7/7/2022 |