FileLogTraceListener TimeStamp , TraceOptions ?

S

semedao

Hi,
how and can I cause the FileLogTraceListener to write the timestamp ,
Callstack etc to the log ?
I mean that it will do it in every Write() , or TraceInformation call

when I tried to add :
traceOutputOptions="ProcessId, DateTime"
I saw that only calling to Trace.TraceError("blabla") will make it !

this is my app.config file:
<system.diagnostics>
<switches>
<add name="TraceSwitchLevel" value = "4" />
</switches>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener,
Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
BaseFileName="xxx" ReserveDiskSpace="1048576000"
DiskSpaceExhaustedBehavior="DiskSpaceExhaustedOption.DiscardMessages"
IncludeHostName="True" Append="False" initializeData="FileLogWriter"
traceOutputOptions="ProcessId, DateTime"/>
</listeners>
</trace>
</system.diagnostics>
 
S

semedao

I saw that the Trace.TraceInformation made it , but the problem isthat I
usually used the
Trace.WriteLineIf(TraceSwitchLevel.TraceVerbose, "blabla", "bla");

and with Trace.TraceInformation it write the data even when
TraceSwitchLevel.TraceVerbose = false

and I want to control the trace from the app.config and not ompilenew
versions every time I want to trace

thanks
 
W

Walter Wang [MSFT]

Hi,

The TraceOptions are only used when using Trace* functions(), when using
Write*() functions, no additional information will be outputed.

As for the WriteLineIf, it's unfortunate that there're no equivalent
Trace*If() functions, however, it's every easy to create a wrap function as:

public static void TraceInformationIf(bool condition, string message)
{
if (condition) Trace.TraceInformation(message);
}

Please let me know if this works for you.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

Dave Sexton

Hi Walter,

The compiler won't optimize out calls to TraceInformationIf when the TRACE symbol isn't defined; however, you can add the following
attribute to accommodate:

[Conditional("TRACE")]
public static void TraceInformationIf(bool condition, string message)
{
...
}
 
W

Walter Wang [MSFT]

Thanks Dave for your reminder.

Hi semedao,

When ConditionalAttribute is applied to a method, it indicates to compilers
that a call to this method should not be compiled into MSIL unless the
conditional compilation symbol associated with ConditionalAttribute is
defined. For more information about this attribute:

http://windowssdk.msdn.microsoft.com/en-us/library/system.diagnostics.condit
ionalattribute(VS.80).aspx

By the way, if you use reflector to view the source of Trace.WriteLineIf,
they are also using this attribute:

[Conditional("TRACE")]
public static void WriteIf(bool condition, object value)
{
TraceInternal.WriteIf(condition, value);
}

Again, thanks Dave for your kind remind.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top