Giter Club home page Giter Club logo

What is it

![](https://raw.github.com/ukoreh/dotnetlog/master/logo.png) A fast and flexible logging and/or diagnostics framework for .NET It allows you to plug it into an existing or new application with minimal changes to the code. Or it can be used as in classic scenarios of logging things along the way at different levels.

Design

Output for "SimpleLogFormatter"

Example One

Task => The logs will go to the storages (persisters) that are indicated in the config file.

<configSections>
	<section name="Logging.Config"
			 type="Logging.Config, Logging" />
	<section name="PlainFile.Config"
			 type="Logging.Persisters.PlainFile.Config, Logging.Persisters.PlainFile" />
</configSections>
<Logging.Config
        verbosity="eDebugs"
        persister="Logging.Persisters.PlainFile" />

<PlainFile.Config
	logFile="C:\\log.log" />    
using Logging;
...
public static void Main()
{ 
	 ILogger logger = LogManager.GetLogger();
			 logger.LogInfo( "Message of logical category" );
			 logger.LogTechnicalInfo( "Message of technical category" );
}

Example Two

Task => Hooking into System.Diagnostics and redirect those logs to a text file.

<configSections>
	<section name="Logging.Config"
			 type="Logging.Config, Logging" />
	<section name="PlainFile.Config"
			 type="Logging.Persisters.PlainFile.Config, Logging.Persisters.PlainFile" />
</configSections>
<system.diagnostics>
	<trace autoflush="true" indentsize="4">
		<listeners>
			<add name="TraceListener.Logger"
				 type="Logging.Adapters.In.TraceListener.Logger, Logging.Adapters.In.TraceListener" />
		</listeners>
	</trace>
</system.diagnostics>
<Logging.Config
	verbosity="eDebugs"
	persister="Logging.Persisters.PlainFile" />

<PlainFile.Config
	logFile="C:\\log.log" />
using System.Diagnostics;
...
public static void Main()
{
		Trace.WriteLine( "Start" );
		Trace.Indent();
			Trace.WriteLine( "aaaaaaaa" );
			Trace.WriteLine( "aaaaaaaa" );
			Trace.WriteLine( "aaaaaaaa" );
			Trace.Indent();
				Trace.WriteLine( "bbbbbbbb" );
				Trace.WriteLine( "bbbbbbbb" );
				Trace.WriteLine( "bbbbbbbb" );
			Trace.Unindent();
		Trace.Unindent();
		Trace.WriteLine( "End" );
}

Example Three

Task => Asynchronous logging to different storages(persisters) + Email notification (just another persister).

What happens with a config like this is that you have in your hands the control to build and shape the pipe through which the logs flow.

1: We want an non blocking call to log API for that reason we use Async module
2: Then by using Multi we want to stock the logs into several storages ( a practical use would be log file and send an email with the error )
3: Each module specified in Multi gets its specific parameters it need to function
4: Done, we start log things we need at Trace level, Debug level and other intermediary levels
<configuration>
    <!-- Logging Definition 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> 
    <configSections> 
        
        <section name="Logging.Config" 
                 type="Logging.Config, Logging" /> 

        <section name="Async.Config" 
                 type="Logging.Modifiers.Async.Config, Logging.Modifiers.Async" /> 

        <section name="Multi.Config" 
                 type="Logging.Modifiers.Multi.Config, Logging.Modifiers.Multi" /> 
        
        <section name="PlainFile.Config" 
                 type="Logging.Persisters.PlainFile.Config, Logging.Persisters.PlainFile" /> 

        <section name="WindowsEventLog.Config" 
                 type="Logging.Persisters.WindowsEventLog.Config, Logging.Persisters.WindowsEventLog" /> 

        <section name="Email.Config" 
                 type="Logging.Persisters.Email.Config, Logging.Persisters.Email" /> 

    </configSections> 

    
    <!-- Logging Configuration 
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> 
    <Logging.Config 
        verbosity="eDebugs" 
        persister="Logging.Modifiers.Async" /> <!-- Means we want all logs till levele "Debug" to flow to the psersister "Async" --> 

    <Async.Config 
        persister="Logging.Modifiers.Multi" /> <!-- Means the "Async" will pass what it gets to the "Multi" in an asynchronous way --> 

    <Multi.Config                              <!-- Multi is specialized to pass what he gets to a list of persisters so they can actually store the logs --> 
        persisters="Logging.Persisters.PlainFile;Logging.Persisters.SystemConsole;Logging.Persisters.WindowsEventLog;Logging.Persisters.Email" /> 

    <PlainFile.Config 
        logFile="C:\\log.log" /> 

    <WindowsEventLog.Config 
        source="Logging.Tester" /> 

    <Email.Config 
        mailServer  ="192.168.1.59" 
        fromMail    ="[email protected]" 
        fromUser    ="user" 
        fromPassword="password" 
        to          ="[email protected]:[email protected]" /> 

</configuration> 

Existing

dotnetlog's Projects

dotnetlog icon dotnetlog

Fast, flexible, small footpring logging and diagnostics framework for .NET

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.