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
<PackageReference Include="MED2020.Utils.Logging" Version="1.0.7" />
paket add MED2020.Utils.Logging --version 1.0.7
#r "nuget: MED2020.Utils.Logging, 1.0.7"
// 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 | Versions 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. |
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 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.