ConnectingApps.CustomCloudLogger 2.0.1

dotnet add package ConnectingApps.CustomCloudLogger --version 2.0.1
NuGet\Install-Package ConnectingApps.CustomCloudLogger -Version 2.0.1
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="ConnectingApps.CustomCloudLogger" Version="2.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ConnectingApps.CustomCloudLogger --version 2.0.1
#r "nuget: ConnectingApps.CustomCloudLogger, 2.0.1"
#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 ConnectingApps.CustomCloudLogger as a Cake Addin
#addin nuget:?package=ConnectingApps.CustomCloudLogger&version=2.0.1

// Install ConnectingApps.CustomCloudLogger as a Cake Tool
#tool nuget:?package=ConnectingApps.CustomCloudLogger&version=2.0.1

CustomCloudLogger

Send messages in a custom format to log analytics workspace in Azure

A LogAnalytics Client for .NET Standard 2.0

The easiest and most generic way to send logs to Azure Log Analytics Workspace from your apps. Just create a custom object and send it to Log Analytics. It will be shown as a log entry in the logs. This helps make logging easy in your applications, regardless of wether you're using .NET Core, .NET Framework, Xamarin, Tizen etc. Almost all .NET variants and versions are supported. The product is inspired by a package developed for .NET Core and .NET 6 named LogAnalytics.Client.

NuGet

The CustomCloudLogger is available on NuGet.

Support for .NET Versions and Variants

As explained, nearly all .NET variants and versions are supported. The DateOnly data type is also supported when using .NET 6 or higher.

How to use the LogAnalytics Client

Installing the package

dotnet add package ConnectingApps.CustomCloudLogger

Use the LogAnalyticsClient

Here is how you can use it:

LogAnalyticsClient _client = new(WorkSpaceId, SharedKey);
var logEntries = new TryData[]
{
    new()
    {
        X = $"Test1 {Environment.MachineName}",
        Y = 1,
    },
    new()
    {
        X = $"Test2 {Environment.MachineName}",
        Y = 2,
    }
};
await _client.LogEntryAsync(logEntries.First(), "TuplesLog");
await _client.LogEntriesAsync(logEntries, "TuplesLog");

In the code shown above, these things are done:

  1. An instance of LogAnalyticsClient is created.
  2. A single log entry is created because of the call to LogEntryAsync.
  3. Multiple log entries are created because of the call to LogEntriesAsync

Do not forget to dispose the client when using this in production code.

A more complete example can be found here.

What do to with Azure?

In case you ran the code above, you'll find your your data in this table:

TuplesLog_CL

A typical KQL query in your log analytics workspace in Azure would look like this:

TuplesLog_CL
| where X_s contains "Test"

If you do not have a shared key to use here, you can generate one:

az monitor log-analytics workspace get-shared-keys --resource-group "YourResourceGroupName" --workspace-name "YourWorkspaceName"

Development

Contribute? Give it a go, but double check if the tests do succeed. I also recommend reading our article about this product.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.1 77 5/16/2024
2.0.0 63 5/13/2024
1.0.1-initial 51 5/13/2024
1.0.0-initial 47 5/13/2024

Updated readme