Skip to content

A opinionated library that makes .NET logging clean to read πŸ‘

License

Notifications You must be signed in to change notification settings

maikebing/PrettyLogging

This branch is 2 commits ahead of, 2 commits behind xiaomi7732/PrettyLogging:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Mar 20, 2025
927bace Β· Mar 20, 2025

History

52 Commits
Mar 20, 2025
Mar 20, 2025
Mar 20, 2025
Mar 20, 2025
Jan 3, 2025
Jan 3, 2025
Jan 3, 2025
Jan 4, 2025
Mar 20, 2025
Mar 20, 2025
Mar 20, 2025
Mar 14, 2025

Repository files navigation

Pretty Logging NuGet Version

Enhance the readability of Microsoft.Extensions.Logging output!

Logging output example

Starting with version 1.0.1, line breaks in single-line logs are now preserved by default.

Line break example

⭐ Show your support! GitHub Repo stars

If you enjoy this project, please give it a ⭐️ to help others discover it!

Have suggestions or found a bug? Open an issue and share your feedback!

Getting Started

  1. Install the NuGet package:

    Add the package to your project by running:

    dotnet add package PrettyLogging.Console
  2. Stay up-to-date with floating versions (optional):

    Use a floating version to always get the latest updates:

    <PackageReference Include="PrettyLogging.Console" Version="[1.*-*, 2.0)" />

    For an example, see UsePrettyLogging.Console.csproj.

  3. Set up Pretty Logging in your app:

    Add the PrettyIt() method to your logger configuration:

    builder.Logging.PrettyIt();
  4. Customize the output (optional):

    Tailor the log output to your needs by adjusting options like log level visibility, timestamp inclusion, log format (single-line or multi-line), color behavior, and more. See Options.md for details.

  5. Enjoy cleaner logs:

    • Console application:

      • Before:

        info: Program[0]
            Hello Pretty Logging
        info: Program[0]
            This is a warning!
        
      • After:

        16:28:30.200|INFO |Hello Pretty Logging
        16:28:30.206|WARN |This is a warning!
        
    • WebAPI:

      • Before:

        info: Microsoft.Hosting.Lifetime[14]
            Now listening on: http://localhost:5140
        info: Microsoft.Hosting.Lifetime[0]
            Application started. Press Ctrl+C to shut down.
        info: Microsoft.Hosting.Lifetime[0]
            Hosting environment: Development
        info: Microsoft.Hosting.Lifetime[0]
            Content root path: C:\AIR\PrettyLogging\examples\UsePrettyLogging.WebAPI
        info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
            Request starting HTTP/1.1 GET http://localhost:5140/ - - -
        info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
            Executing endpoint 'HTTP: GET /'
        info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
            Executed endpoint 'HTTP: GET /'
        info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
            Request finished HTTP/1.1 GET http://localhost:5140/ - 200 - text/plain;+charset=utf-8 36.5664ms
        
      • After:

        17:56:08.734|INFO |Now listening on: http://localhost:5140
        17:56:08.740|INFO |Application started. Press Ctrl+C to shut down.
        17:56:08.740|INFO |Hosting environment: Development
        17:56:08.740|INFO |Content root path: C:\AIR\PrettyLogging\examples\UsePrettyLogging.WebAPI
        17:56:18.280|INFO |Request starting HTTP/1.1 GET http://localhost:5140/ - - -
        17:56:18.316|INFO |Executing endpoint 'HTTP: GET /'
        17:56:18.319|INFO |Executed endpoint 'HTTP: GET /'
        17:56:18.327|INFO |Request finished HTTP/1.1 GET http://localhost:5140/ - 200 - text/plain;+charset=utf-8 41.9690ms
        

About

A opinionated library that makes .NET logging clean to read πŸ‘

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 98.9%
  • Shell 1.1%