Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace messages with Trace and Debug levels are emitted without trace event type #21

Open
ATECoder opened this issue Feb 26, 2021 · 0 comments

Comments

@ATECoder
Copy link

... as a result, these messages cannot be filtered. I suggest changing this:

`

    public void Emit(LogEvent logEvent)
    {
        if (logEvent == null) throw new ArgumentNullException(nameof(logEvent));
        var sr = new StringWriter();
        _textFormatter.Format(logEvent, sr);

        var text = sr.ToString().Trim();

        if (logEvent.Level == LogEventLevel.Error || logEvent.Level == LogEventLevel.Fatal)
            Trace.TraceError(text);
        else if (logEvent.Level == LogEventLevel.Warning)
            Trace.TraceWarning(text);
        else if (logEvent.Level == LogEventLevel.Information)
            Trace.TraceInformation(text);
        else
            Trace.WriteLine(text);
    }

`
to this:

`

    public void Emit(LogEvent logEvent)
    {
        if (logEvent == null) throw new ArgumentNullException(nameof(logEvent));
        var sr = new StringWriter();
        _textFormatter.Format(logEvent, sr);

        var text = sr.ToString().Trim();

        if (logEvent.Level == LogEventLevel.Error || logEvent.Level == LogEventLevel.Fatal)
            Trace.TraceError(text);
        else if (logEvent.Level == LogEventLevel.Warning)
            Trace.TraceWarning(text);
        else
            Trace.TraceInformation(text);
    }

`

A better granularity could be had if Trace had exposed the TraceEvent method, of the TraceInternal class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant