MED2020.Utils.Logging 1.0.7

A simple application logger.

Install-Package MED2020.Utils.Logging -Version 1.0.7
dotnet add package MED2020.Utils.Logging --version 1.0.7
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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);
    }
}

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);
    }
}

Release Notes

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.

Dependencies

This package has no dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.7 83 5/18/2019
1.0.6 94 4/2/2019