Giter VIP home page Giter VIP logo

logging-1's Introduction

Core Techs Logging

Features

  • Lightweight
  • Simple API
  • No dependencies
  • Asynchronous by default
  • Logging exceptions won't crash your app

Getting Started

0. Installation

PM> Install-Package CoreTechs.Logging

1. Create a LogManager instance

The log manager should be a long lived object in your application. It's responsible for coordinating LogEntry's and Target's.

The preferred way to create and initialize the LogManager is to use the Configure method:

var logManager = LogManager.Configure("logging");

And in the app.config:

<configSections>
	<section name="logging" type="CoreTechs.Logging.Configuration.ConfigSection, CoreTechs.Logging" />
</configSections>
<logging>
	<!-- logging targets are defined here -->
	<target type="Console" />
</logging>

Notice the name of the configuration section is passed into the Configure method.

You could also configure the LogManager in the application code, if you're into that:

var console = new ConsoleTarget();
var logManager = new LogManager(new[] {console});

2. Create a Logger instance

When you want to log something, you'll need a Logger instance. Typically, you'll create one as a field in each class that writes to the log:

// create a logger with the same name as the current class
private readonly Logger Log = _logManager.GetLoggerForCallingType();

The logger's name ends up being the Source property of each written log entry. You can name the logger anything you like:

var logger = new Logger(logManager, "My happy logger");

3. Write to the log

Use the Logger instance (referenced by Log below) to write to the log targets:

Log.Trace("A small detail");
Log.Debug("Something {0} is going on.", "fishy");
Log.Data("Username", "roverby")
	.Data("Email", "[email protected]")
	.Info("A user has logged into the system.");

if (TooManyIncorrectLoginAttempts)
	Log.Data("Username", username)
		.Warn("A user may be trying to break into the system.");

try
{
	SomethingDangerous();
}
catch (TolerableException ex)
{
	Log.Exception(ex).Error();
}
catch (Exception ex)
{
	Log.Exception(ex).Fatal();
	throw;
}

Targets

	throw new NotImplementedException(); // :)

logging-1's People

Contributors

ronnieoverby avatar zshazz avatar

Watchers

Ajay Anand avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.