Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Introducing My Logging Library

DZone's Guide to

Introducing My Logging Library

· DevOps Zone
Free Resource

Download the blueprint that can take a company of any maturity level all the way up to enterprise-scale continuous delivery using a combination of Automic Release Automation, Automic’s 20+ years of business automation experience, and the proven tools and practices the company is already leveraging.

I’ve just published the first version (consider it a beta) of my logging library to the official nuget server(s).

Why another library when there are existing ones as log4net and nlog? Because it should be easier to get started and you should still have the power to customize the logging if needed. Griffin.Logging do not have a configuration file, everything is configured through code.

Simple syntax

The easiest approach only requires one line to configure the framework:

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

You can swap the AddFile method to AddConsole if you would like.

Fluent syntax

Use the fluent syntax if you need more power:

var config = new FluentConfiguration()
  .LogNamespace("Fadd.Test").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)
        {
            // Log an exception. The inner exceptions are logged too (recursive)
            logger.Warning("Ooops, we got an exception.", ex);
        }
    }
 
}

Code

Check the homepage for more information or just install the nuget package “griffin.logging“.


Download the ‘Practical Blueprint to Continuous Delivery’ to learn how Automic Release Automation can help you begin or continue your company’s digital transformation.

Topics:

Published at DZone with permission of Jonas Gauffin, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}