kdheath.Logging.Helper
2.0.3
Prefix Reserved
See the version list below for details.
dotnet add package kdheath.Logging.Helper --version 2.0.3
NuGet\Install-Package kdheath.Logging.Helper -Version 2.0.3
<PackageReference Include="kdheath.Logging.Helper" Version="2.0.3" />
paket add kdheath.Logging.Helper --version 2.0.3
#r "nuget: kdheath.Logging.Helper, 2.0.3"
// Install kdheath.Logging.Helper as a Cake Addin #addin nuget:?package=kdheath.Logging.Helper&version=2.0.3 // Install kdheath.Logging.Helper as a Cake Tool #tool nuget:?package=kdheath.Logging.Helper&version=2.0.3
About
The Logging.Helper package is a light-weight platform for .NET with rich log routing and management capabilities provided by NLog.
See Change Log for release notes.
Key Features
- Supports .NET Framework, .NET Core, and .NET 5.0+
- By default, logging will only be output to the console window.
How to Use
To use in a C# program:
using Logging.Helper;
internal static readonly Logger sLogger = new( typeof( Program ) );
Logging can be performed using:
sLogger.Debug( "Logging a debug message" );
sLogger.Info( "Logging a information message" );
sLogger.Warn( "Logging a warning message" );
sLogger.Error( "Logging an error message" );
sLogger.Error( "With exception", ex );
Note: sLogger.Log
can also be used to log an informational message.
To allow a processing class to log using the logger created in the main program it must inherit from the Logging.Helper.LoggerEvent
class.
The processing class would look something like this:
using System;
using Logging.Helper;
public class ProcessingClass : LoggerEvent
{
internal int DoProcessing()
{
var retValue = 0; // Assume normal completion
try
{
// This method is inherited from the LoggerEvent class
RaiseLogEvent( "Information message about the processing..." );
}
catch( Exception ex )
{
RaiseLogEvent( ex.ToString(), LogSeverity.Fatal );
retValue = -1; // Abnormal completion
}
return retValue;
}
}
The raise log handler must be set for the ProcessingClass
object so that it will use the internal logger defined in the main program.
// Create an object from a class that inherits LoggerEvent
var logicClass = new ProcessingClass();
logicClass.RaiseLogHandler += Logging.OnRaiseLog;
// Do Processing and set the Exit code
logicClass.DoProcessing();
Advanced Logging
To enable advanced NLog logging create a nlog.config
(all lowercase) file in the root of your application project and set the file Property: Copy if newer.
- For detailed information about NLog configurations Configuration File.
- For tutorials and documentation see the NLog Wiki site.
Example XML for a stand-alone NLog.config:
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target xsi:type="File" name="logfile" fileName="c:\temp\console-example.log"
layout="${longdate} ${uppercase:${level:padding=-5}} ${message}"/>
<target xsi:type="Console" name="logconsole"
layout="${longdate} ${uppercase:${level:padding=-5}} ${message}"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logconsole" />
<logger name="*" minlevel="Debug" writeTo="logfile" />
</rules>
</nlog>
Main Types
Logger
- Class that provides common logging properties and methods.LoggerEvent
- Base class to handle logging using an event handler.LoggerEventArgs
- Common event arguments to use when logging a message.
Feedback
This is provided as open source under the MIT license.
Bug reports and contributions are welcome at the GitHub repository.
Product | Versions 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. |
-
.NETStandard 2.0
- kdheath.Application.Helper (>= 2.0.1)
- NLog (>= 5.2.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
* Applied code refactoring based on the unit test results.