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.

Re: Using Trace class by John

John
Tue Dec 14 12:20:01 CST 2004

"Oleg Ogurok" <oleg@ogurok.com.ihatespammers.ireallydo.co> wrote in message
news:10rub92ci4lst2a@corp.supernews.com...
> 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