Simple example of Trace to file

791 views
Skip to first unread message

Patrick O'Beirne

unread,
Sep 25, 2012, 7:50:28 AM9/25/12
to exce...@googlegroups.com
I see that in VS 2010 Express adding a .config file generates defaults like this:

            <add name="FileLog"
                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
                 initializeData="FileLogWriter"/>


But how are they used? I've added lines like
Trace.WriteLine("ActiveCell address: " & cell.Address(External:=True))

but no output file called FileLogWriter or anything else is created.

MSDN examples are pretty opaque eg
http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/25fd387a-ca88-4ac6-8aee-8e208a4e66cd/

 and I've gone around in circles looking at examples but am still not clear how much is done in myaddinname.config and how much in the code.

I've tried
        Trace.Listeners.Add(New TextWriterTraceListener("TestPIA.debug.log"))
        Trace.WriteLine("ActiveCell address: " & cell.Address(External:=True))

and the output file TestPIA.debug.log gets created but has 0 bytes when I exit Excel.

Can you give me a starter simple example, like how to use Trace.Writeline, or capture Debug.Print to a file?

TIA

Patrick






Govert van Drimmelen

unread,
Sep 25, 2012, 8:20:36 AM9/25/12
to Excel-DNA
Hi Patrick,

The sample \Distribution\Samples\Packing\PackConfig\ actually has
a .dna file and .config file that does the tracing to a file C:
\PackConfig.log. I just used it to test the .config file packing, but
it works as a sample for what you ask too.

For your own test, you can check:
* Is your config file called "MyAddInName.xll.config", and next to
MyAddInName.xll? Only those files are loaded by Excel-DNA as the
config file for the AppDomain.
* I see that I had to #define TRACE for it to work with the C#. Maybe
you need something similar in VB.NET (if it is not the default).

Regards,
Govert


On Sep 25, 2:11 pm, "Patrick O'Beirne" <obeirne....@gmail.com> wrote:
> I see that in VS 2010 Express adding a .config file generates defaults
> like this:
>
>              <add name="FileLog"
> type="Microsoft.VisualBasic.Logging.FileLogTraceListener,
> Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
>                   initializeData="FileLogWriter"/>
>
> But how are they used? I've added lines like
> Trace.WriteLine("ActiveCell address: " & cell.Address(External:=True))
>
> but no output file called FileLogWriter or anything else is created.
>
> MSDN examples are pretty opaque eghttp://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/25fd387...

Patrick O'Beirne

unread,
Sep 25, 2012, 10:17:59 AM9/25/12
to exce...@googlegroups.com
Thanks, Govert, the example told me what I needed to know.
I needed to name the file as MyAddInName.xll.config and set Copy To
Output to If Newer.
I needed to define a <trace....> section. I don't (yet, AFAIK) need the
<sources...> stuff that VS automatically adds.

In VB.Net, TRACE and DEBUG are automatically defined, in VS it's in
Project > Properties > Compile > Advanced

Thanks again!

P
Reply all
Reply to author
Forward
0 new messages