Microsoft.Extensions.Logging.Console 9.0.0

About

Microsoft.Extensions.Logging.Console provides a Console logger provider implementation for Microsoft.Extensions.Logging. It provides extension methods for the ILoggingBuilder and ILoggerProviderConfiguration classes.

Key Features

How to Use

using System;
using Microsoft.Extensions.Logging;

namespace ConsoleLoggerSample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a logger factory with a console provider
            using ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());

            // Create a logger with the category name of the current class
            ILogger<Program> logger = loggerFactory.CreateLogger<Program>();

            // Log some messages with different log levels and message templates
            logger.LogTrace("This is a trace message.");
            logger.LogDebug("This is a debug message.");
            logger.LogInformation("Hello {Name}!", "World");
            logger.LogWarning("This is a warning message.");
            logger.LogError("This is an error message.");
            logger.LogCritical("This is a critical message.");

            // Use structured logging to capture complex data
            var person = new Person { Name = "Alice", Age = 25 };
            logger.LogInformation("Created a new person: {@Person}", person);

            // Use exception logging to capture the details of an exception
            try
            {
                throw new Exception("Something went wrong.");
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "An exception occurred.");
            }

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }

    // A simple class to demonstrate structured logging
    class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
    }
}

Main Types

The main types provided by this library are:

  • ConsoleLoggerProvider
  • ConsoleLoggerSettings
  • ConsoleLoggerOptions
  • ConsoleLoggerExtensions
  • ConsoleFormatter
  • ConsoleFormatterOptions
  • JsonConsoleFormatterOptions
  • SimpleConsoleFormatterOptions

Additional Documentation

Microsoft.Extensions.Logging.Abstractions Microsoft.Extensions.Logging Microsoft.Extensions.Logging.Debug Microsoft.Extensions.Logging.EventSource Microsoft.Extensions.Logging.EventLog Microsoft.Extensions.Logging.TraceSource

Feedback & Contributing

Microsoft.Extensions.Logging.Console is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Showing the top 20 packages that depend on Microsoft.Extensions.Logging.Console.

Packages Downloads
MTNT.UTILS
修改了运行计时输出都控制台info
3,593
MTNT.UTILS
将项目重新分离
2,010
MTNT.UTILS
将项目重新分离
1,768
MTNT.UTILS
修改了运行计时输出都控制台info
437
Microsoft.AspNetCore
Microsoft.AspNetCore
312
MTNT.UTILS
修改了运行计时输出都控制台info
190
MTNT.UTILS
修改了运行计时输出都控制台info
185
MTNT.UTILS
修改了运行计时输出都控制台info
175
MTNT.UTILS
修改了运行计时输出都控制台info
170
MTNT.UTILS
修改了运行计时输出都控制台info
149
MTNT.UTILS
修改了运行计时输出都控制台info
96
MTNT.UTILS
修改了运行计时输出都控制台info
64
MTNT.UTILS
修改了运行计时输出都控制台info
56
Microsoft.AspNetCore
Microsoft.AspNetCore
48
MTNT.UTILS
修改了运行计时输出都控制台info
46
MTNT.UTILS
修改了运行计时输出都控制台info
44
Microsoft.AspNetCore
Microsoft.AspNetCore
44

https://go.microsoft.com/fwlink/?LinkID=799421

Version Downloads Last updated
9.0.0 10 11/13/2024
9.0.0-rc.2.24473.5 14 10/17/2024
9.0.0-rc.1.24431.7 18 09/12/2024
9.0.0-preview.7.24405.7 21 08/13/2024
9.0.0-preview.6.24327.7 15 07/11/2024
9.0.0-preview.5.24306.7 33 06/12/2024
9.0.0-preview.4.24266.19 26 05/23/2024
9.0.0-preview.3.24172.9 24 04/13/2024
9.0.0-preview.2.24128.5 23 03/20/2024
9.0.0-preview.1.24080.9 29 02/14/2024
8.0.1 10 10/11/2024
8.0.0 37 11/14/2023
8.0.0-rc.2.23479.6 40 10/22/2023
8.0.0-rc.1.23419.4 42 09/22/2023
8.0.0-preview.7.23375.6 48 08/09/2023
8.0.0-preview.6.23329.7 36 07/12/2023
8.0.0-preview.5.23280.8 45 06/20/2023
8.0.0-preview.4.23259.5 32 06/09/2023
8.0.0-preview.3.23174.8 33 07/05/2023
8.0.0-preview.2.23128.3 42 06/20/2023
8.0.0-preview.1.23110.8 31 08/18/2023
7.0.0 33 05/17/2023
7.0.0-rc.2.22472.3 32 09/29/2023
7.0.0-rc.1.22426.10 26 06/20/2023
7.0.0-preview.7.22375.6 44 07/14/2023
7.0.0-preview.6.22324.4 17 09/24/2023
7.0.0-preview.5.22301.12 27 10/28/2023
7.0.0-preview.4.22229.4 16 06/20/2023
7.0.0-preview.3.22175.4 15 10/02/2023
7.0.0-preview.2.22152.2 28 09/30/2023
7.0.0-preview.1.22076.8 34 06/19/2023
6.0.2-mauipre.1.22102.15 37 10/28/2023
6.0.2-mauipre.1.22054.8 31 06/08/2023
6.0.1 6 11/13/2024
6.0.0 317 02/11/2022
6.0.0-rc.2.21480.5 28 09/29/2023
6.0.0-rc.1.21451.13 24 07/22/2023
6.0.0-preview.7.21377.19 33 06/19/2023
6.0.0-preview.6.21352.12 28 09/30/2023
6.0.0-preview.5.21301.5 34 06/08/2023
6.0.0-preview.4.21253.7 31 10/03/2023
6.0.0-preview.3.21201.4 28 06/19/2023
6.0.0-preview.2.21154.6 30 07/05/2023
6.0.0-preview.1.21102.12 48 06/08/2023
5.0.0 38 06/11/2021
5.0.0-rc.2.20475.5 30 08/18/2023
5.0.0-rc.1.20451.14 27 10/28/2023
5.0.0-preview.8.20407.11 29 10/10/2023
5.0.0-preview.7.20364.11 21 10/24/2023
5.0.0-preview.6.20305.6 30 08/07/2023
5.0.0-preview.5.20278.1 30 06/08/2023
5.0.0-preview.4.20251.6 18 10/06/2023
5.0.0-preview.3.20215.2 29 10/02/2023
5.0.0-preview.2.20160.3 24 07/28/2023
5.0.0-preview.1.20120.4 42 09/12/2023
3.1.32 43 07/23/2023
3.1.31 27 07/04/2023
3.1.30 32 10/04/2023
3.1.29 47 06/20/2023
3.1.28 54 06/20/2023
3.1.27 33 09/21/2023
3.1.26 25 10/09/2023
3.1.25 35 06/22/2023
3.1.24 46 06/20/2023
3.1.23 43 08/16/2023
3.1.22 44 06/13/2023
3.1.21 47 07/05/2023
3.1.20 48 06/20/2023
3.1.19 39 06/20/2023
3.1.18 36 09/30/2023
3.1.17 52 10/04/2023
3.1.16 39 10/03/2023
3.1.15 33 06/20/2023
3.1.14 31 10/14/2023
3.1.13 40 07/04/2023
3.1.12 25 10/06/2023
3.1.11 37 09/12/2023
3.1.10 28 11/12/2023
3.1.9 49 06/20/2023
3.1.8 31 09/30/2023
3.1.7 48 06/20/2023
3.1.6 25 09/22/2023
3.1.5 37 09/23/2023
3.1.4 46 07/28/2023
3.1.3 7,168 12/16/2020
3.1.2 51 06/20/2023
3.1.1 28 09/24/2023
3.1.0 48 06/20/2023
3.1.0-preview3.19553.2 24 09/11/2023
3.1.0-preview2.19525.4 37 06/25/2023
3.1.0-preview1.19506.1 42 06/20/2023
3.0.3 35 09/05/2023
3.0.2 40 09/20/2023
3.0.1 28 09/22/2023
3.0.0 47 09/06/2023
3.0.0-rc1.19456.10 27 09/30/2023
3.0.0-preview9.19423.4 30 09/28/2023
3.0.0-preview8.19405.4 38 09/22/2023
3.0.0-preview7.19362.4 35 08/18/2023
3.0.0-preview6.19304.6 34 07/31/2023
3.0.0-preview5.19227.9 38 09/11/2023
3.0.0-preview4.19216.2 25 10/02/2023
3.0.0-preview3.19153.1 44 06/20/2023
3.0.0-preview.19074.2 40 08/22/2023
3.0.0-preview.18572.1 31 10/17/2023
2.2.0 40 09/25/2023
2.2.0-preview3-35497 29 08/28/2023
2.2.0-preview2-35157 27 10/06/2023
2.2.0-preview1-35029 24 10/01/2023
2.1.1 25 08/19/2023
2.1.0 35 06/20/2023
2.1.0-rc1-final 31 06/20/2023
2.1.0-preview2-final 47 09/29/2023
2.1.0-preview1-final 30 09/30/2023
2.0.2 55 06/24/2023
2.0.1 49 09/30/2023
2.0.0 339 01/18/2021
2.0.0-preview2-final 45 06/20/2023
2.0.0-preview1-final 29 10/10/2023
1.1.2 36 09/12/2023
1.1.1 37 08/26/2023
1.1.0 48 06/20/2023
1.1.0-preview1-final 28 09/18/2023
1.0.2 41 07/04/2023
1.0.1 33 06/20/2023
1.0.0 47 07/05/2023
1.0.0-rc2-final 40 08/19/2023
1.0.0-rc1-final 55 06/20/2023