Konnect.Log4NetAlaAppender
1.0.0
See the version list below for details.
dotnet add package Konnect.Log4NetAlaAppender --version 1.0.0
NuGet\Install-Package Konnect.Log4NetAlaAppender -Version 1.0.0
<PackageReference Include="Konnect.Log4NetAlaAppender" Version="1.0.0" />
paket add Konnect.Log4NetAlaAppender --version 1.0.0
#r "nuget: Konnect.Log4NetAlaAppender, 1.0.0"
// Install Konnect.Log4NetAlaAppender as a Cake Addin #addin nuget:?package=Konnect.Log4NetAlaAppender&version=1.0.0 // Install Konnect.Log4NetAlaAppender as a Cake Tool #tool nuget:?package=Konnect.Log4NetAlaAppender&version=1.0.0
Konnect.Log4NetAlaAppender
This is a small, but hopefully a production-grade Log4Net adapter for Azure Log Analytics.
This appender uses BufferedAppenderSkeleton class from Log4Net, which allows this project to be free of concerns such as buffering and flushing.
The log messages are sent using the Log Analytics Data Collector API asynchronously (using Task.Run), but failed attempts are not retried currently.
Captured fields
Currently, Log4net.Core.LoggingEvent objects are mapped to JSON (as required by the Data Collector API) using this code:
var eventsToSend = events.Select(e => new
{
Level = e.Level.Name,
e.LoggerName,
Message = e.RenderedMessage,
e.TimeStamp,
e.Identity,
e.ThreadName,
e.UserName,
Exception = e.GetExceptionString()
});
var json = JsonConvert.SerializeObject(eventsToSend);
The mapping function is currently not configurable.
Usage
Add this appender description in your Log4Net configuration:
<appender name="AzureLogAppender" type="Konnect.Log4NetAzureLogAnalytics.KnlAlaAppender, Konnect.Log4NetAlaAppender">
<WorkspaceId>#{YourWorkspaceId}</WorkspaceId>
<SharedKey>#{YourSharedKey}</SharedKey>
<LogType>#{YourLogType}</LogType>
</appender>
And then, add you can reference this logger from the logger configuration - for example:
<root>
<level value="INFO" />
<appender-ref ref="AzureLogAppender" />
</root>
There is a Debug feature, in case there is a problem with connectivity - you can set the EnableDebugLog option in the appender configuration like this:
<appender name="AzureLogAppender" type="Konnect.Log4NetAzureLogAnalytics.KnlAlaAppender, Konnect.Log4NetAlaAppender">
<WorkspaceId>#{YourWorkspaceId}</WorkspaceId>
...
<EnableDebugLog>true</EnableDebugLog>
</appender>
The debug output will be sent to the Console as well as the Debug output, which can be viewed through tools such as SysInternal's DebugView
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net471 is compatible. net472 was computed. net48 was computed. net481 was computed. |
-
- log4net (>= 2.0.3)
- Newtonsoft.Json (>= 9.0.1)
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 |
---|---|---|
1.1.7026.17263 | 620 | 3/27/2019 |
1.0.0 | 666 | 11/6/2018 |
Initial release