Skip to content

How to filter log messages being passed to a logging provider? #1205

@girishjjain

Description

@girishjjain

It appears to me that a logging provider gets all log messages including ones generated by aspnet framework. Is there a way to filter that? For example, I added a logging provider as follows:

loggerFactory.AddTraceSource(
    new SourceSwitch("SystemSwitch", "Verbose"),
    new TextWriterTraceListener("ServiceLog.txt", "SystemTrace"));

And I see whole lot of information in the ServiceLog.txt file, as follows:

Microsoft.AspNet.Hosting.Internal.HostingEngine Verbose: 4 : Hosting starting
Microsoft.AspNet.Hosting.Internal.HostingEngine Verbose: 5 : Hosting started
Microsoft.AspNet.Hosting.Internal.HostingEngine Information: 1 : Request starting HTTP/1.1 DEBUG http://localhost:50193/ text/html 
Microsoft.AspNet.Hosting.Internal.HostingEngine Information: 1 : Request starting HTTP/1.1 GET http://localhost:50193/api/values  
..
SystemTrace Verbose: 0 : 12/29/2015 22:02:18: Invoking method UserRepository::GetUser

But I want to use this logging provider only for service specific log entries i.e. the last log entry above which is logged by my service code. So currently, I see log entries for framework events too. How do I filter it for a certain logging provider? Or what would be the recommended approach to achieve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions