Giter VIP home page Giter VIP logo

Comments (4)

savarobert avatar savarobert commented on September 6, 2024 1

One quick workaround was to inherit the NLogTargetListener and add my own logic to bypass the verbosity of the text log:

public class NLogCustomTargetListener : NLogTargetListener, ILogListener
{
    public new void OnBeginRequest(KissLog.Web.HttpRequest httpRequest, ILogger logger)
    {
        if (httpRequest.Url.PathAndQuery.IndexOf("/swagger/", StringComparison.InvariantCultureIgnoreCase) >= 0)
        {
            return;
        }
        base.OnBeginRequest(httpRequest, logger);
    }
}

In the web interface everything works the same, as expected.

from kisslog.sdk.

catalingavan avatar catalingavan commented on September 6, 2024 1

If it works, keep it a while :)
I will update SDK to provide more flexibility for this scenario. I will keep you updated.

from kisslog.sdk.

catalingavan avatar catalingavan commented on September 6, 2024

Hi Robert,

The NLogTargetListener is sending the logs to NLog as soon as they get executed in the code.

This implies that, by the time LogListenerParser.ShouldLog(FlushLogArgs args) is evaluating the condition, the logs have already been saved to text files.

Below is the execution workflow:

Begin GET /swagger/         <---- start of the request


_logger.Debug("step 1");    <---- "step 1" is sent to NLog (text file)
_logger.Debug("step 2");    <---- "step 2" is sent to NLog (text file)
...
_logger.Debug("step n");    <---- "step n" is sent to NLog (text file)


                            <---- by this time, the log messages have already been sent to the NLog targets

							
END 200 OK GET /swagger/    <---- end of the request
                            <---- ShouldLog(FlushLogArgs args) is executed at this step

One possible solution would be to update the LogListenerParser and provide callback for the BeginRequest event.

public class LogListenerParser
{
    // will get executed just at the beginning of the request
    // if return false, the listener will not listen for any logs for the current request
    public virtual bool ShouldLog(BeginRequestArgs args)
    {
        if (args.Request.Url.LocalPath.Contains("/swagger/"))
            return false;

        return true;
    }

    public virtual bool ShouldLog(FlushLogArgs args, ILogListener logListener)
    {
        return true;
    }
}

from kisslog.sdk.

catalingavan avatar catalingavan commented on September 6, 2024

Published KissLog 3.5.1 which fixes this issue.

Updated LogListenerParser with one new method:

public class LogListenerParser
{
    public virtual bool ShouldLog(BeginRequestArgs args, ILogListener logListener)
    {
        return true;
    }
}

This method gets executed at the begging of the request.

If the result is false, the Listener will stop logging the current request.

Begin GET /swagger/         <---- start of the request
                            <---- ShouldLog(BeginRequestArgs args) is executed
                            <---- if false, skip;


_logger.Debug("step 1");    <---- skipped
_logger.Debug("step 2");    <---- skipped
...
_logger.Debug("step n");    <---- skipped

							
END 200 OK GET /swagger/    <---- end of the request

from kisslog.sdk.

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.