Beispiel #1
0
        /// <summary>
        /// This example shows how to use logging with a very simple console logger that does not need any extra references.
        /// </summary>
        private static void LogWithSimpleProvider()
        {
            LogDispatcher.LoggerFactory = new SimpleConsoleLoggerFactory();

            var testee = new MyTestComponent();

            testee.DoSomeLogging();
            LogDispatcher.LoggerFactory = null;
        }
Beispiel #2
0
        /// <summary>
        /// This example shows how to enable logging to the console by using the implementations in
        /// Microsoft.Extensions.Logging.dll and Microsoft.Extensions.Logging.Console.dll. Both packages need to be referenced.
        /// </summary>
        private static void LogWithStandardProvider()
        {
            using var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder
                .AddConsole();
            });

            // Statically register our factory. Note that this must be done before instantiation of any class that wants to use logging.
            LogDispatcher.LoggerFactory = loggerFactory;

            var testee = new MyTestComponent();

            testee.DoSomeLogging();
            LogDispatcher.LoggerFactory = null;
        }