Skip to content

enkomio/Fslog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FSLOG - F# Log

"FSLOG - F# Log" is a simple yet powerful logging framework written in order to be used with a semantic approach in mind.

A .NET Core version is also availbel as Nuget package: https://www.nuget.org/packages/ES.Fslog.Core

Using FSLOG

On F#:

Define your logging source:

type MyLogger() =
    inherit LogSource("MyLogger")

    [<Log(1, Message = "Hello: {0}", Level = LogLevel.Informational)>]
    member this.SayHelloTo(name: String) =
        this.WriteLog(1, [|name|])

    [<Log(2, Message = "Pay attention {0} !!!", Level = LogLevel.Critical)>]
    member this.SayPayAttentionTo(name: String) =
        this.WriteLog(2, [|name|])

Configure your log provider:

let logProvider = new LogProvider()
logProvider.AddLogger(new ConsoleLogger(LogLevel.Informational))

Now you can add the log source to the log provider and forget about the last one:

let logSource = new MyLogger()
logProvider.AddLogSourceToLoggers(logSource)

Call the methods on your log source to start to log messages:

logSource.SayPayAttentionTo("John")
logSource.SayHelloTo("Michael")

Fluent Interface

It is higly suggested to use the fluent interface in order to create your log source. It allows to write more compact and elegant code. The Fluent interface is based on the Builder pattern. Let's try to rewrite the example above with the Fluent interface:

let logSource =
    log "MyLogger"
    |> info "SayHello" "Hello: {0}"
    |> critical "SayPayAttentionTo" "Pay attention {0} !!!"
    |> build

and that's all! After that you have added the log source to the log provider (as described above), you can use it by relying on the ? operator:

logSource?SayPayAttentionTo("John")
logSource?SayHelloTo("Michael")

You can skip the last step by creating the logSource and adding it to the logProvider at the same time with the buildAndAdd method as shown in the following piece of code:

let logSource =
    log "MyLogger"
    |> info "SayHello" "Hello: {0}"
    |> critical "SayPayAttentionTo" "Pay attention {0} !!!"
    |> buildAndAdd logSource

logSource?SayHelloTo("Michael")

The other supported methods are: verbose, warning and error.


On C#:

Define your logging source:

internal sealed class StubLogSource : LogSource
{
    public MyLogger()
        : base("MyLogger")
    { }

    [Log(1, Level = LogLevel.Informational, Message = "Hello {0}")]
    public void SayHelloTo(String name)
    {
        this.WriteLog(1, name);
    }

    [Log(2, Level = LogLevel.Critical, Message = "Pay attention {0} !!!")]
    public void SayPayAttentionTo(String name)
    {
        this.WriteLog(2, name);
    }
}

Configure your log provider:

var logProvider = new LogProvider();
logProvider.AddLogger(new ConsoleLogger(LogLevel.Informational));

Now you can add the log source to the log provider and forget about the last one:

var logSource = new MyLogger();
logProvider.AddLogSourceToLoggers(logSource);

Call the methods on your log source to start to log messages:

logSource.SayPayAttentionTo("John");
logSource.SayHelloTo("Michael");

How to get FSLOG

You can download the source code from https://github.com/enkomio/Fslog/archive/master.zip.

FSLOG is also available on NuGet. To install the tool, run the following command in the Package Manager Console:
PM> Install-Package FSharpLog

or for .NET Core

PM> Install-Package ES.Fslog.Core

License information

Copyright (C) 2014-2016 Antonio Parata

License: GNU General Public License, version 2 or later; see COPYING.txt included in this archive for details.

About

Fslog is a simple yet powerful F# logging framework

Resources

License

Unknown, GPL-2.0 licenses found

Licenses found

Unknown
LICENSE.md
GPL-2.0
COPYING

Stars

Watchers

Forks

Packages

No packages published

Languages