kdheath.Logging.Helper 1.0.2

Prefix Reserved
Additional Details

The source repository no longer exists.

There is a newer version of this package available.
See the version list below for details.
dotnet add package kdheath.Logging.Helper --version 1.0.2                
NuGet\Install-Package kdheath.Logging.Helper -Version 1.0.2                
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="kdheath.Logging.Helper" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add kdheath.Logging.Helper --version 1.0.2                
#r "nuget: kdheath.Logging.Helper, 1.0.2"                
#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 kdheath.Logging.Helper as a Cake Addin
#addin nuget:?package=kdheath.Logging.Helper&version=1.0.2

// Install kdheath.Logging.Helper as a Cake Tool
#tool nuget:?package=kdheath.Logging.Helper&version=1.0.2                

About

The Logging.Helper package is a light-weight platform for .NET with rich log routing and management capabilities provided by NLog.

Key Features

  • Supports .NET Framework, .NET Core, and .NET 5.0+
  • By default, logging will only be output to the console window.

Change Log

  • v1.0.2
    • Package name prefix changed to kdheath.
    • Remove strong-signing of assemblies.
  • v1.0.1 Updated to use NLog 5
  • v1.0.0
    • Uses NLog 4
    • Target framework updated to .NET Standard 2.0

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.

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 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.8 85 10/11/2024
2.0.7 113 9/5/2024
2.0.6 123 7/3/2024
2.0.5 115 5/1/2024
2.0.4 155 4/1/2024
2.0.3 233 2/17/2024
2.0.2 277 2/7/2024
2.0.1 466 12/8/2023
2.0.0 395 11/30/2023
1.0.3 342 11/21/2023 1.0.3 is deprecated.
1.0.2 382 11/11/2023 1.0.2 is deprecated.