Skip to content

jmptrader/Griffin.Logging

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Griffin.Logging is a Logging framework for .NET similar to log4net and NLog.

The difference is all in the syntax.

Configuration

You can either use the simple interface to get going quickly:

SimpleLogManager.Instance.AddFile(@"D:\LogFiles\MyLog.log");
SimpleLogManager.Instance.AddConsole(false);

Or the fluent syntax:

new FluentConfiguration()
	.LogNamespace("ConsoleApplication1").AndChildNamespaces.ToTargetNamed("Console")
	.LogNamespace("System").AndChildNamespaces.ToTargetNamed("DefaultFile")
	.AddTarget("Console")
		.As.ConsoleLogger().Filter.OnLogLevelBetween(LogLevel.Info, LogLevel.Error)
		.Done
	.AddTarget("DefaultFile")
		.As.FileLogger("ErrorsOnly").Filter.OnLogLevel(LogLevel.Error)
		.As.FileLogger("Everything")
		.Done
	.Build();

Usage

public class MyClass
{
	ILogger logger = LogManager.GetLogger<MyClass>();
 
	public MyClass()
	{
		// Built in formatting for cleaner syntax.
		logger.Info("Welcome {0}!.", user.Name);
	}
	public void HideError()
	{
		try
		{
			throw new InvalidOperationException("No no", new OutOfScopeException("Can't thing anymore"));
		}
		catch (Exception err)
		{
			// exceptions details are properly formatted.
			logger.Warning("Ooops, we got an exception.", ex);
		}
	}
}

Installation (nuget)

Install-Package griffin.logging

You can also send all entries over MQ (great for clients)

Install-Package griffin.logging.mq 

Extending

  • Create a custom logmanager by implementing ILogManager and assign it using [LogManager.Assign].
  • Create a custom target by implementing ILogTarget. Look at AdoNetTarget for an example
  • Add a IPreFilter or a IPostFilter to filter log entries.
  • Create extension methods for one of the FluentXXX classes to inject your custom classes to the fluent configuration.

About

A Logging framework for .NET

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%