Using Trace class

O

Oleg Ogurok

Hi all,

I have a .NET object exposed to a COM (VB6) application. When the
application calls the .NET methods, I'd like to use Trace.WriteLineIf() to
log trace info into an event log.
Usually with ASP.NET application, one can control the TraceLevel of a
TraceSwitch in web.config, and for WindowsForms or console applications, in
App.config file.

However, in this case I only have a shared library (assembly). How would I
control the trace level in this scenario?


Also I'm thinking of using Trace.WriteLineIf(mySwithch.TraceError, "error:
.....") instead of calling EventLog.WriteEntry(....,
EventLogEntryType.Error). The problem is that all events are logged as type
"Information". Is there a way to tell Trace class to log an event as type
"Error"?



Thanks,

-Oleg.
 
J

John Saunders

Oleg Ogurok said:
Hi all,

I have a .NET object exposed to a COM (VB6) application. When the
application calls the .NET methods, I'd like to use Trace.WriteLineIf() to
log trace info into an event log.
Usually with ASP.NET application, one can control the TraceLevel of a
TraceSwitch in web.config, and for WindowsForms or console applications,
in App.config file.

However, in this case I only have a shared library (assembly). How would I
control the trace level in this scenario?

Your problem is twofold:

1) In the case of a dll assembly, the config file used is the application's
config file
2) In your case, there is no managed application, just a VB6 application, so
there is no config file!

You could define your own subclass of System.Diagnostics.Switch (or maybe of
TraceSwitch) which gets its values from somewhere else. I once wrote one
which gets its values from the command line of the installutil
application...
Also I'm thinking of using Trace.WriteLineIf(mySwithch.TraceError, "error:
....") instead of calling EventLog.WriteEntry(....,
EventLogEntryType.Error). The problem is that all events are logged as
type "Information". Is there a way to tell Trace class to log an event as
type "Error"?

Not in .NET Framework 1.0 or 1.1. They appear to be fixing this in 2.0.

John Saunders
 

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