Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
Damian Hickey edited this page Sep 6, 2018 · 9 revisions

Install the nuget package which contains the source and which will automatically set the namespace to your project's root namespace (if using Visual Studio).

Using a logger inside your library

public class MyClass
{
    private static readonly ILog Logger = LogProvider.For<MyClass>(); 
    
    public MyClass()
    {
        using(LogProvider.OpenNestedContext("message"))
        using(LogProvider.OpenMappedContext("key", "value"))
        {
            Logger.Info(....);
        }
    }
}

By default only your code will only be able to get a logger from within your library (assuming it's a single assembly). This is by design to prevent consumers of your library creating unintended coupling your library's log provider.

From their perspective, intellisense will look like this:

If you have a scenario where you have a single "core" project in a solution and you want LibLog's various GetLogger() methods available to other projects in your solutions, consider first using [InternalsVisibleTo] attribute.

Alternatively you may optionally make the various GetLogger() public by defining LIBLOG_PUBLIC conditional compilation symbol. Your consumer's intellisense will look like this:

** Be wary though of your consumers potentially creating unintended coupling your library's log provider. **

Diagnostic Contexts

Diagnostic contexts can be opened from the LogProvider:

        using (logProvider.OpenNestedContext("nestedmessage"))
        {
            //...
        }

        using (logProvider.OpenMappedContext("key", "value"))
        {
            //...
        }