Giter Club home page Giter Club logo

Comments (2)

github-actions avatar github-actions commented on September 14, 2024

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

from zlogger.

robertmircea avatar robertmircea commented on September 14, 2024

If the issue is still valid for you, the only solution I found it working is to use the following prefix formatting:

    logging.AddZLoggerConsole(options =>
    {
        var prefixFormat = ZString.PrepareUtf8<int, int, int, int, int, int, int, LogLevel>("{0:D4}-{1:D2}-{2:D2} {3:D2}:{4:D2}:{5:D2}.{6:D3} [{7}] ");
        options.PrefixFormatter = (writer, info) =>
        {
            var nowLocalTime = info.Timestamp.DateTime.ToLocalTime();
            prefixFormat.FormatTo(ref writer,
                nowLocalTime.Year,
                nowLocalTime.Month,
                nowLocalTime.Day,
                nowLocalTime.Hour,
                nowLocalTime.Minute,
                nowLocalTime.Second,
                nowLocalTime.Millisecond,
                info.LogLevel);
        };
    });

This is because Zlogger uses Utf8Formatter.TryFormat from Microsoft, and this function does not support formatting dates with other formats apart from what is documented at Utf8Formatter.TryFormat. So instead of using DateTime, I deconstruct the current date time in its constituents (year, month, day, hours, etc.) and then use one of the PrepareUtf8 generic overloads to format those integers in date format. D4, D2, D3 formats for integers are passed by the library directly to Utf8Formatter.TryFormat to format with 4, 2 or 3 leading digits in total including the leading zero if necessary.

The above code produces the following log messages:

2022-12-30 01:09:07.298 [Information] Now listening on: http://localhost:5178
2022-12-30 01:09:07.299 [Information] Application started. Press Ctrl+C to shut down.
2022-12-30 01:09:07.299 [Information] Hosting environment: Development

from zlogger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.