Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Logging custom objects #159

Closed
mikernet opened this issue Mar 14, 2018 · 4 comments
Closed

Logging custom objects #159

mikernet opened this issue Mar 14, 2018 · 4 comments

Comments

@mikernet
Copy link

mikernet commented Mar 14, 2018

If I can make a suggestion - it is rather useful to have a version of the logging methods with this signature and implementation:

        public static void Debug<T>(this ILog logger, T message)
        {
            if (logger.IsDebugEnabled())
            {
                logger.Log(LogLevel.Debug, message?.ToString().AsFunc());
            }
        }

This allows logging of custom objects without boxing / allocating a closure / allocating a delegate / unnecessarily executing ToString() if the log isn't enabled.

I find it is also nice to have some overloads for the methods with params object[] parameters for calls with less than a few params to avoid the array allocation in those cases.

For most cases this won't be significant of course, but those allocations can really add up with tracing level calls.

@damianh
Copy link
Owner

damianh commented May 27, 2018

Sorry for slow response, parked liblog work pending .pp transform support for sdk csprojs.

On the face of this a reasonable suggestion. Would you care to try a PR for this, see if it works out?

@darkl
Copy link
Contributor

darkl commented May 28, 2018

For the first idea: you can implement this by writing your own extension method:

public static class LogExtensions
{
    public static void Debug<T>(this ILog log, T message)
    {
        log.Debug(() => message?.ToString());
    }
}

@aivarasgg
Copy link

This feature would be super useful. We have some custom hooks which fill in some additional metadata depending on the type of message, so sending some object through to the logging library would help us a lot,
I had a look at the logging libraries that LibLog currently supports and it seems like all of them accept either object or have a generic function like Debug<T>(T message) to get any type of message logged.

@damianh
Copy link
Owner

damianh commented Dec 4, 2019

In light of #270 , closing this.

@damianh damianh closed this as completed Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants