I am writing a web api in .NET 6. I don't seem to find a sample where I can write to custom tables under Azure Log Analytics . They can be written to via posting a json payload, I was hoping there would be a nuget package library that can already do that taking a workspaceId and sharedkey for access.
Azure Log Analytics is compatible with the following frameworks .NET Core, .NET 5 and .NET 6.
To write custom data collections to Log Analytics using wrapper
Install-Package LogAnalytics.Client
LogAnalytics_Wrapper logger = new LogAnalytics_Wrapper(
workspaceId: "Workspace id,
sharedKey: "Shared key");
await logger.SendLogEntry(new SomeEntity
{
Category = GetCategory(),
SomeString = $"String Test",
SomeBoolean = true,
SomeDateTime = DateTime.UtcNow,
SomeDouble = 2.1,
SomeGuid = Guid.NewGuid()
}, "testlog")
.ConfigureAwait(false); ConfigureAwait(false)
Log entries using wrapper
LogAnalyticsClient logger = new LogAnalyticsClient(
workspaceId: "Workspace id",
sharedKey: "Shared KEY");
List<DemoEntity> entities = new List<DemoEntity>();
for (int i = 0; i < 1000; ii++)
{
entities.Add(new DemoEntity
{
Criticality = GetCriticality(),
Message = "Message",
SystemSource = GetSystemSource()
});
}
await logger.SendLogEntries(entities, "testlog").ConfigureAwait(false)
We can fetch the workspaceId and shared key values from appsettings.json or KeyVault
Fetching the logs from azure using the below command
search *
| where Type == "testlog_CL"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.