Microsoft.Extensions.Logging.Console 9.0.1

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,600
MTNT.UTILS
将项目重新分离
2,016
MTNT.UTILS
将项目重新分离
1,859
MTNT.UTILS
修改了运行计时输出都控制台info
445
Microsoft.AspNetCore
Microsoft.AspNetCore
338
MTNT.UTILS
修改了运行计时输出都控制台info
196
MTNT.UTILS
修改了运行计时输出都控制台info
191
MTNT.UTILS
修改了运行计时输出都控制台info
182
MTNT.UTILS
修改了运行计时输出都控制台info
177
MTNT.UTILS
修改了运行计时输出都控制台info
156
MTNT.UTILS
修改了运行计时输出都控制台info
102
MTNT.UTILS
修改了运行计时输出都控制台info
101
MTNT.UTILS
修改了运行计时输出都控制台info
71
MTNT.UTILS
修改了运行计时输出都控制台info
62
Microsoft.AspNetCore
Microsoft.AspNetCore
56
MTNT.UTILS
修改了运行计时输出都控制台info
54
Microsoft.AspNetCore
Microsoft.AspNetCore
52
MTNT.UTILS
修改了运行计时输出都控制台info
51
Microsoft.AspNetCore
Microsoft.AspNetCore
51

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

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