Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF tracing & message logging - trace level warning

Assume I have a config file which looks like this: ...

<system.diagnostics>
  <sources>
    <source name="System.ServiceModel" switchValue="Warning,ActivityTracing" propagateActivity="true">
      <listeners>
        <add name="ServiceModelTraceListener" />
      </listeners>
    </source>
    <source name="System.ServiceModel.MessageLogging">
      <listeners>
        <add name="ServiceModelTraceListener" />
      </listeners>
    </source>
  </sources>
  <sharedListeners>
    <add initializeData="LogServer.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="ServiceModelTraceListener" />
  </sharedListeners>
  <trace autoflush="true" />
</system.diagnostics>

When using this config file every activity the caller performs against the service and each corresponding message that's sent to the service will be logged in the svclog file. Everything fine so far.

If I modify the 3rd line from the above listing to <source name="System.ServiceModel" switchValue="Warning" propagateActivity="true"> (the ActivityTracing is removed) then only those activities are logged that are at least labeled level warning. But it's still every message logged...

So is there a way to only log those message that correspond to those activities that are at least warnings? Those messages that succeeded aren't very interesting in that moment, but those messages that belong to the unsuccessful activities are!

like image 710
Jan Köhler Avatar asked Nov 14 '22 22:11

Jan Köhler


1 Answers

Edit To filter messages beyond the options below you may want to look into writing your own TraceSource.

Below is one I am using for a project. You could easily customize it to filter out the messages you want or perhaps hide activity if it is not in DEBUG, etc.

class DB : TraceSource
{
    public DB(string name) : base(name)
    { 
    }

    public DB(string name, SourceLevels sourceLevels) : base (name, sourceLevels)
    { 
    } 

    public void Log(object value)
    {
        WriteLine(value);
    }

    public void Error(object value)
    {
        WriteLine(value, TraceEventType.Error);
    }

    public void Error(RecordingResponseData errorResponse)
    {
        string errorMessage = "[Error] Code: "+errorResponse.ErrorCode +" Message: "+errorResponse.ErrorMessage;
        WriteLine(errorMessage, TraceEventType.Error);
    }

    public void Warn(object value)
    {
        WriteLine(value, TraceEventType.Warning);
    }

    public void WriteLine(object value, TraceEventType type = TraceEventType.Information)
    { 
        TraceEvent(type, 0, value.ToString());
    }


}

Original

Your options are:

  1. Critical
  2. Error
  3. Warning
  4. Information
  5. ActivityTracing
  6. Verbose
  7. All

Or a combination there of. If you have it set to Warning but are still getting too many messages then you may want to try Error or Critical.

ref: https://msdn.microsoft.com/en-us/library/ms733025%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

like image 118
ickydime Avatar answered Dec 06 '22 07:12

ickydime