Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ILogger in static context #7

Open
tincann opened this issue May 25, 2018 · 0 comments
Open

Use ILogger in static context #7

tincann opened this issue May 25, 2018 · 0 comments

Comments

@tincann
Copy link

tincann commented May 25, 2018

Hi there,

I was wondering if it is possible to make use of a static ILogger. My code contains a special wrapper class which adds some metadata and is also responsible to format log messages in a consistent way. What I tried was exposing the ILogger from the wrapper class (SpecialLogger in the example), and setting it as the globally shared logger. I'm using this logger through out multiple assemblies, so using the ILogger injected into the webjob function isn't an option to me.

Example:

class Program
    {
        public static readonly SpecialLogger SpecialLogger = SpecialLogger.Create("Test");

        static void Main()
        {
            // Here I try to make the underlying ILogger globally shared
            Log.Logger = SpecialLogger.Logger;

            var config = new JobHostConfiguration();
            config.UseSerilog();

            var host = new JobHost(config);
            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant