user3587624 user3587624 - 1 year ago 89
C# Question

Get rid of the Project Name.vshost.exe from the Trace ouput

I have defined a Trace Listener on my console application like this

ConsoleTraceListener = new ConsoleTraceListener();
AutoFlush = true;

And then several
calls through all my source code.

The point is that when I execute the code on the command line, I can see the following thing on each of the Traces:

  • MyNewSampleProject.vshost.exe Information: 0 : Starting...

  • MyNewSampleProject.vshost.exe Information: 0 : Creating Profile...

How can I get rid of the

MyNewSampleProject.vshost.exe Information: 0:.

I am just interested in knowing the message that I set in the Trace.


Answer Source

Unfortunately this seems not possible.

I decompiled that listener and found, that there is no option to this. But there's still hope.

You can implement your own Listener like this:

  public class MyListener : ConsoleTraceListener {

   public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message) {
        if (this.Filter != null && !base.Filter.ShouldTrace(eventCache, source, eventType, id, message, null, null, null))

    private bool IsEnabled(TraceOptions opts) {
        return (uint) (opts & this.TraceOutputOptions) > 0U;

    private void WriteFooter(TraceEventCache eventCache) {
        if (eventCache == null)
        this.IndentLevel = this.IndentLevel + 1;
        if (this.IsEnabled(TraceOptions.ProcessId))
            this.WriteLine("ProcessId=" + (object) eventCache.ProcessId);
        if (this.IsEnabled(TraceOptions.LogicalOperationStack)) {
            Stack logicalOperationStack = eventCache.LogicalOperationStack;
            bool flag = true;
            foreach (object obj in logicalOperationStack) {
                if (!flag)
                    this.Write(", ");
                    flag = false;
        if (this.IsEnabled(TraceOptions.ThreadId))
            this.WriteLine("ThreadId=" + eventCache.ThreadId);
        if (this.IsEnabled(TraceOptions.DateTime))
            this.WriteLine("DateTime=" + eventCache.DateTime.ToString("o", (IFormatProvider) CultureInfo.InvariantCulture));
        if (this.IsEnabled(TraceOptions.Timestamp))
            this.WriteLine("Timestamp=" + (object) eventCache.Timestamp);
        if (this.IsEnabled(TraceOptions.Callstack))
            this.WriteLine("Callstack=" + eventCache.Callstack);
        this.IndentLevel = this.IndentLevel - 1;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download