Thanks for Juan and Peter's informative resource.
Hi Martyn,
As for using the "My.Log" object (VB.NET specific ) to log information in
ASP.NET 2.0 web application, you need to do the following configuration:
1. First register a text file listener in the web.config if you want to
write the trace log into text file. e.g.
===========
<system.diagnostics>
..................
<sharedListeners>
<add name="FileLogListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="d:\temp\web_app_log.txt"/>
</sharedListeners>
</system.diagnostics>
===========
Be careful that we should not use the
"Microsoft.VisualBasic.Logging.FileLogTraceListener" class here because the
"Microsoft.VisualBasic.Logging.FileLogTraceListener" class will always look
for a path in the current user's Local application directory( and this path
doesn't exist for the ASP.NET service account, "Network Service" or
"machine\ASPNET"). Therefore, we use the
System.Diagnostics.TextWriterTraceListener class instead(if you want, you
can use some other XML Trace Listeners under that namespace too)
2. Add a switch under the <switches> section like:
===========
<system.diagnostics >
.............
<switches >
<add name="DefaultSwitch" value="Verbose" />
</switches>
..............
============
This is used to control what level information will be logged(and other
level information will be ignored)
#Configuring Trace Switches
http://msdn.microsoft.com/library/en-us/vbcon/html/vbconconfigurationoftrace
switches.asp?frame=true
3. After add the Listener and Switch elements, we need to add the "Source"
element for our My.Log object.
==================
<system.diagnostics >
.............................
<sources >
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLogListener"/>
</listeners>
</source>
..................
=================
This "DefaultSource" will be used by our VB.NET My.Log object and we
reference the "FileLogListener" configured previously.
In addition, we should add the <trace autoflush="true" ></trace> to make
the runtime immediately write out trace after we call My.Log.Writexxxx
So the complete configuration section will look like below:
===============================
<system.diagnostics >
<trace autoflush="true" ></trace>
<sources >
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLogListener"/>
</listeners>
</source>
</sources>
<switches >
<add name="DefaultSwitch" value="Verbose" />
</switches>
<sharedListeners>
<add name="FileLogListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="d:\temp\web_app_log.txt"/>
</sharedListeners>
</system.diagnostics>
===================================
You can put it in your application's web.config file and use My.Log object
to write trace log. BTW, make sure your ASP.NET servcie identity has
sufficient permission to modify log files in the certain path we specified
in the above <sharedListeners>. like:
==============
<add name="FileLogListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="d:\temp\web_app_log.txt"/>
==============
BTW, the following msdn document describes most information about
configuration of My.Log object( and add custom listeners for it). However,
there is one error in it. We should not use the
"Microsoft.VisualBasic.Logging.FileLogTraceListener" class for ASP.NET
application as I mentioned above, just take care of this.
#Walkthrough: Changing Where My.Application.Log Writes Information
http://msdn2.microsoft.com/en-us/library/5cz98azz.aspx
If you have anything unclear or any further questions, please feel free to
post here.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
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.