Skip to content

A Fay Logging facade for Microsoft Enterprise Library Logging

License

Notifications You must be signed in to change notification settings

FayLibs/Fay.Logging.EntLib5

Repository files navigation

Fay Logging EntLib5

What is it?

It is a Fay Logging facade for the Microsoft Enterprise Library Logging Application Block version 5. This facade provides a simple delegate logging API making logging easier, while helping to make sure any of the code required to generate a log message is not executed unless the logging level is within scope.

Quick Start

Below is a simplified example for logging strings when you don't use categories. A more robust implementation may use a service locator or dependency inject framework to initialize the logger.

    // Initialize logger someplace
    IDelegateLogger<string> logger = new EntLibSimpleMessageLogger(Logger.Writer);
    
    // Use logger as needed
    logger.Critical(() => string.Format("Some text blah {0} blah", "blah"));
    
    logger.Verbose(() =>
    {
        StringBuilder builder = new StringBuilder();
        builder.Append("Foo");
        builder.Append(" ");
        builder.Append("Bar");
        return builder.ToString();
    });
    
    // When application is done needing the logger its recommend to dispose it
    logger.Dispose();

Below is a simple example for logging to categories.

    // Initialize logger someplace
    IDelegateLogger<MessageWithCategories> logger = new EntLibSimpleCategoryLogger(Logger.Writer);
    
    // Use logger as needed
    logger.Critical(() => new MessageWithCategories(string.Format("Some text blah {0} blah", "blah"), "General", "Foo"));
    
    logger.Verbose(() =>
    {
        StringBuilder builder = new StringBuilder();
        builder.Append("Foo");
        builder.Append(" ");
        builder.Append("Bar");
        return new MessageWithCategories(builder.ToString(), "General", "Foo");
    });
    
    // When application is done needing the logger its recommend to dispose it
    logger.Dispose();

Downloads

Fey Logging EntLib 5 is available via NuGet:

About

A Fay Logging facade for Microsoft Enterprise Library Logging

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages