MED2020.Utils.Logging 1.0.7

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

// Install MED2020.Utils.Logging as a Cake Tool
#tool nuget:?package=MED2020.Utils.Logging&version=1.0.7

MED2020 Logging

A simple logging utility for applications.

Release Notes

Version 1.0.6
  • Fix: call to Log.Dispose() flushes loggers.
Version 1.0.5
  • Allow name to be specified via AddTarget method.

Simplest

Simplest way to get started. Logs are saved by default to "[ApplicationPath]\logs" in html.

using MED2020.Utils.Logging;

class Program
{
        static ILogger log;

        static void Main(string[] args)
        {
            Log.LogFactory.Initialize();
            log = Log.GetLogger(); // returns default logger

            var x = log.Exception(new Exception(), "Exception message");
            //throw x;
            log.Error("Error message");
            log.Warning("Generic message");
            log.Header("Header message");
            log.Message("Generic message");
            log.Details("Details message");
            log.Trace("Trace message", stackSkip:1, stackDepth:5);
    }
}

Specify Path

How to choose which path to save logs in.

using MED2020.Utils.Logging;

class Program
{
        static ILogger log;

        static void Main(string[] args)
        {
            var target = Log.Configuration.AddTarget(LogTargetType.Html, LogLevelType.Details);
            var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            target.LogDir = Path.Combine(localAppData, "ApplicationName", "logs");

            Log.LogFactory.Initialize();
            log = Log.GetLogger(); // returns default logger

            var x = log.Exception(new Exception(), "Exception message");
            //throw x;
            log.Error("Error message");
            log.Warning("Generic message");
            log.Header("Header message");
            log.Message("Generic message");
            log.Details("Details message");
            log.Trace("Trace message", stackSkip:1, stackDepth:5);
    }
}

Access Log After Initialized

using MED2020.Utils.Logging;

class AnotherClass
{
    static readonly ILogger log = Log.GetLogger();

    public void DoSomething()
    {
        log.Message("Beginning something");

        try
        {
            // do something here.
        }
        catch(Exception x)
        {
            log.Exception(x, "Something bad happened");
            throw;
        }

        log.Message("Finished something");
    }
}

Set Log Level

How to choose which level logging will be done at.

Capture just Exceptions, Errors and Warnings

using MED2020.Utils.Logging;

class Program
{
        static ILogger log;

        static void Main(string[] args)
        {
            var logLevel = LogLevelType.Warnings;
            var target = Log.Configuration.AddTarget(LogTargetType.Html, logLevel);
            Log.LogFactory.Initialize();
            log = Log.GetLogger(); // returns default logger

            // Items that get logged
            var x = log.Exception(new Exception(), "Exception message"); 
            //throw x;
            log.Error("Error message");
            log.Warning("Generic message");

            // Items that get omitted
            log.Header("Header message");
            log.Message("Generic message");
            log.Details("Details message");
            log.Trace("Trace message", stackSkip:1, stackDepth:5);
    }
}

Capture Everything but Trace

using MED2020.Utils.Logging;

class Program
{
        static ILogger log;

        static void Main(string[] args)
        {
            var logLevel = LogLevelType.Details;
            var target = Log.Configuration.AddTarget(LogTargetType.Html, logLevel);
            Log.LogFactory.Initialize();
            log = Log.GetLogger(); // returns default logger

            // Items that get logged
            var x = log.Exception(new Exception(), "Exception message"); 
            //throw x;
            log.Error("Error message");
            log.Warning("Generic message");
            log.Header("Header message");
            log.Message("Generic message");
            log.Details("Details message");

            // Items that get omitted
            log.Trace("Trace message", stackSkip:1, stackDepth:5);
    }
}

Enable Trace

using MED2020.Utils.Logging;

class Program
{
        static ILogger log;

        static void Main(string[] args)
        {
            var logLevel = LogLevelType.Trace;
            var target = Log.Configuration.AddTarget(LogTargetType.Html, logLevel);
            Log.LogFactory.Initialize();
            log = Log.GetLogger(); // returns default logger

            // Items that get logged
            var x = log.Exception(new Exception(), "Exception message"); 
            //throw x;
            log.Error("Error message");
            log.Warning("Generic message");
            log.Header("Header message");
            log.Message("Generic message");
            log.Details("Details message");
            log.Trace("Trace message", stackSkip:1, stackDepth:5);
    }
}
Product Compatible and additional computed target framework versions.
.NET Framework net452 is compatible.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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.0.7 597 5/18/2019
1.0.6 513 4/2/2019

Version 1.0.7
     - Added Split() function that starts a new Log file for filebased loggers.

     Version 1.0.6
     - Fix: call to Log.Dispose() flushes loggers.

     Version 1.0.5
     - Allow name to be specified via AddTarget method.