473,503 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing Exceptions to the Application Log

Hi there

I'm trying to find the correct way to write exceptions to the Application
log using Vb.Net.

I've done a fair bit of Googleing and although this gets plenty of mentions
and that this is apparently the correct way forward nobody offers a solution
as to how it is actually done.

I gather that code like:

Try
'my code goes here
Catch ex As Exception
My.Log.WriteException(ex)
End Try

Will write the exception to a listener but there is no mention of how a
listener is set up on a web App and how this is configured to write to the
Application Log (Security permissions etc)

Plenty of the on line info suggest a Registry hack but this doesnt seem
appropiatte.

PS. I do find it ironic that if i dont catch the exception it gets written
to the log by default.

Thanks for your help.

Martyn


--
Regards

Martyn Fewtrell
Jul 30 '06 #1
12 6030
Don't bother writing to the Application log.

Peter Bromberg outlines a much better way to log exceptions in this article :

http://www.eggheadcafe.com/articles/20030816.asp

Read the article...and download his sampl code at :
http://www.eggheadcafe.com/articles/20030816.zip


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Martyn Fewtrell" <mf*******@newsgroup.nospamwrote in message
news:69**********************************@microsof t.com...
Hi there

I'm trying to find the correct way to write exceptions to the Application
log using Vb.Net.

I've done a fair bit of Googleing and although this gets plenty of mentions
and that this is apparently the correct way forward nobody offers a solution
as to how it is actually done.

I gather that code like:

Try
'my code goes here
Catch ex As Exception
My.Log.WriteException(ex)
End Try

Will write the exception to a listener but there is no mention of how a
listener is set up on a web App and how this is configured to write to the
Application Log (Security permissions etc)

Plenty of the on line info suggest a Registry hack but this doesnt seem
appropiatte.

PS. I do find it ironic that if i dont catch the exception it gets written
to the log by default.

Thanks for your help.

Martyn


--
Regards

Martyn Fewtrell

Jul 30 '06 #2
Thanks to Juan for the mention, actually I have an even more "Generic"
implementation of that here:

http://www.eggheadcafe.com/articles/20060531.asp

However, if you really want to write to the Event Log, take a look at the
System.Diagnostics Namepace. There are static methods there for this.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Martyn Fewtrell" wrote:
Hi there

I'm trying to find the correct way to write exceptions to the Application
log using Vb.Net.

I've done a fair bit of Googleing and although this gets plenty of mentions
and that this is apparently the correct way forward nobody offers a solution
as to how it is actually done.

I gather that code like:

Try
'my code goes here
Catch ex As Exception
My.Log.WriteException(ex)
End Try

Will write the exception to a listener but there is no mention of how a
listener is set up on a web App and how this is configured to write to the
Application Log (Security permissions etc)

Plenty of the on line info suggest a Registry hack but this doesnt seem
appropiatte.

PS. I do find it ironic that if i dont catch the exception it gets written
to the log by default.

Thanks for your help.

Martyn


--
Regards

Martyn Fewtrell
Jul 30 '06 #3
Ahh...
Thanks for that update, Peter.

Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.comwrote in message
news:6F**********************************@microsof t.com...
Thanks to Juan for the mention, actually I have an even more "Generic"
implementation of that here:

http://www.eggheadcafe.com/articles/20060531.asp

However, if you really want to write to the Event Log, take a look at the
System.Diagnostics Namepace. There are static methods there for this.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Martyn Fewtrell" wrote:
>Hi there

I'm trying to find the correct way to write exceptions to the Application
log using Vb.Net.

I've done a fair bit of Googleing and although this gets plenty of mentions
and that this is apparently the correct way forward nobody offers a solution
as to how it is actually done.

I gather that code like:

Try
'my code goes here
Catch ex As Exception
My.Log.WriteException(ex)
End Try

Will write the exception to a listener but there is no mention of how a
listener is set up on a web App and how this is configured to write to the
Application Log (Security permissions etc)

Plenty of the on line info suggest a Registry hack but this doesnt seem
appropiatte.

PS. I do find it ironic that if i dont catch the exception it gets written
to the log by default.

Thanks for your help.

Martyn

Jul 31 '06 #4
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.FileLogTraceListene r" class here because the
"Microsoft.VisualBasic.Logging.FileLogTraceListene r" 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 <switchessection 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...urationoftrace
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" ></traceto 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.FileLogTraceListene r" 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/subscripti...ult.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/subscripti...t/default.aspx.

==================================================

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

Jul 31 '06 #5
Thanks for all the responses, I'll take a look through and see what suits the
situation best.

I have to say the solution for "Dummies" sounds appealing!
--
Regards

Martyn Fewtrell
"Steven Cheng[MSFT]" wrote:
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.FileLogTraceListene r" class here because the
"Microsoft.VisualBasic.Logging.FileLogTraceListene r" 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 <switchessection 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...urationoftrace
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" ></traceto 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.FileLogTraceListene r" 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/subscripti...ult.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/subscripti...t/default.aspx.

==================================================

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

Jul 31 '06 #6
Once again thanks for all the replies.

Steven

The information you have sent me is great apart from the fact that I do
actually want to write the information to the application log. I appreciate
the principal follows through the same logic. Therefore I assume the line:

<sharedListeners>
<add name="FileLogListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="d:\temp\web_app_log.txt"/>

</sharedListeners>

needs to be something different? Something like:

<sharedListeners>
<add name="ApplicationLogListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="something different in here?"/>

</sharedListeners>

Note the "Something different in here?"

After this I think the real issue is the comment:

"make sure your ASP.NET service identity has sufficient permission to modify
log files in the certain path we specified"

which is fine for a folder on the local drive where I can give access
(Read/Write etc) for the Network Service account but what I don’t know is
what user writes does which account need to write to the Application Log and
where do I set this.

Again I assume this is the Network Service account on ASP.Net 2.0 with Win
Server 2003 (IIS6) but what writes does it need and how are they set?

Thanks again for your comprehensive answer.

--
Regards

Martyn Fewtrell
"Steven Cheng[MSFT]" wrote:
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.FileLogTraceListene r" class here because the
"Microsoft.VisualBasic.Logging.FileLogTraceListene r" 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 <switchessection 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...urationoftrace
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" ></traceto 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.FileLogTraceListene r" 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/subscripti...ult.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/subscripti...t/default.aspx.

==================================================

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

Jul 31 '06 #7
Hi Martyn,

Just found that I've missed the point that you're wantting to write the
error message into "Event Log" (I previously think that the "Application
Log" you mentioned means a custom application log file). If so, you should
replace the text file listener with an EventLog Trace Listener class.
The "System.Diagnostics.EventLogTraceListener" class is a built-in class
which is capable of this. Here is a modified configuratino section that use
both text file and eventlog trace listener:

===============================
<system.diagnostics >
<trace autoflush="true" ></trace>
<sources >
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLogListener"/>
<add name="EventLogListener" />
</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"/>

<add name="EventLogListener"
type="System.Diagnostics.EventLogTraceListener,
System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
initializeData="Application"/>
</sharedListeners>
</system.diagnostics>
===================================

also, take care of the "initializeData" attribute in the eventlog listener
configuration element.

=============
<add name="EventLogListener"
.............................
initializeData="Application"/>
</sharedListeners>
=====================

Here I set it to "Application" because ASP.NET worker process identity(such
as Network Service) can only write to the "Application" source in the
eventlog, if you change to other value, that means you would write to a
"Custom Event Source". Then you may get "Access Denied" error, in such
cases, you need to grant the ASP.NET process identity sufficient permission
to write into that custom event source (of course you need to create the
custom event source first if it doesn't exist originally).

Hope this also helps. If you have anything unclear, please feel free to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Jul 31 '06 #8
Thanks Steven

I have managed to write to a text file on the hard drive based on your
earlier post so that bit worked fine. I'll try these later modifications and
get back to you if I get stuck.

Once again thanks!
--
Regards

Martyn Fewtrell
"Steven Cheng[MSFT]" wrote:
Hi Martyn,

Just found that I've missed the point that you're wantting to write the
error message into "Event Log" (I previously think that the "Application
Log" you mentioned means a custom application log file). If so, you should
replace the text file listener with an EventLog Trace Listener class.
The "System.Diagnostics.EventLogTraceListener" class is a built-in class
which is capable of this. Here is a modified configuratino section that use
both text file and eventlog trace listener:

===============================
<system.diagnostics >
<trace autoflush="true" ></trace>
<sources >
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLogListener"/>
<add name="EventLogListener" />
</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"/>

<add name="EventLogListener"
type="System.Diagnostics.EventLogTraceListener,
System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
initializeData="Application"/>
</sharedListeners>
</system.diagnostics>
===================================

also, take care of the "initializeData" attribute in the eventlog listener
configuration element.

=============
<add name="EventLogListener"
.............................
initializeData="Application"/>
</sharedListeners>
=====================

Here I set it to "Application" because ASP.NET worker process identity(such
as Network Service) can only write to the "Application" source in the
eventlog, if you change to other value, that means you would write to a
"Custom Event Source". Then you may get "Access Denied" error, in such
cases, you need to grant the ASP.NET process identity sufficient permission
to write into that custom event source (of course you need to create the
custom event source first if it doesn't exist originally).

Hope this also helps. If you have anything unclear, please feel free to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Jul 31 '06 #9
Steven

Thats great my Test Application works fine so I can now transfer it across
to the real project. I guess I need myself a good book on Web Config files
and what can and can't be added etc.

--
Regards

Martyn Fewtrell
"Steven Cheng[MSFT]" wrote:
Hi Martyn,

Just found that I've missed the point that you're wantting to write the
error message into "Event Log" (I previously think that the "Application
Log" you mentioned means a custom application log file). If so, you should
replace the text file listener with an EventLog Trace Listener class.
The "System.Diagnostics.EventLogTraceListener" class is a built-in class
which is capable of this. Here is a modified configuratino section that use
both text file and eventlog trace listener:

===============================
<system.diagnostics >
<trace autoflush="true" ></trace>
<sources >
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLogListener"/>
<add name="EventLogListener" />
</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"/>

<add name="EventLogListener"
type="System.Diagnostics.EventLogTraceListener,
System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
initializeData="Application"/>
</sharedListeners>
</system.diagnostics>
===================================

also, take care of the "initializeData" attribute in the eventlog listener
configuration element.

=============
<add name="EventLogListener"
.............................
initializeData="Application"/>
</sharedListeners>
=====================

Here I set it to "Application" because ASP.NET worker process identity(such
as Network Service) can only write to the "Application" source in the
eventlog, if you change to other value, that means you would write to a
"Custom Event Source". Then you may get "Access Denied" error, in such
cases, you need to grant the ASP.NET process identity sufficient permission
to write into that custom event source (of course you need to create the
custom event source first if it doesn't exist originally).

Hope this also helps. If you have anything unclear, please feel free to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Jul 31 '06 #10
Thanks for your quick reply,

Seems you are much quicker than I have expected since I'm just trying to
reply your another previous message. However, you have already got it
working now :-).

As you mentioned that you'll transfer the test project to your real
project(is it in another machine and environment?), I suggest you make
further check to ensure that your current test application's enviornment
setting is mostly identitcal to the real one's. Such as the security
context/identity that runs the application. This can help avoid some
unexpected erros when move to the target place.

As always, if you meet any further problems on this, please feel free to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Jul 31 '06 #11
let's not forget the enterprise library logging block as well

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:bO**************@TK2MSFTNGXA01.phx.gbl...
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.FileLogTraceListene r" class here because
the
"Microsoft.VisualBasic.Logging.FileLogTraceListene r" 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 <switchessection 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...urationoftrace
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" ></traceto 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.FileLogTraceListene r" 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/subscripti...ult.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/subscripti...t/default.aspx.

==================================================

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



Aug 1 '06 #12
Thanks for your input Alvin,

Yes, the enterprise library's exception handling block has much improved in
2.0.

BTW, I've also read Peter's article and found that his logging component is
quite similar with EntLib's exception handling block , at least from the
syntax :-)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Aug 1 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1047
by: Ehab Teima | last post by:
Hello, I have built a server application. It's multithreaded, and everything works fine so far. I have only one issue with catching exceptions after I read the documentation but I can't find any...
24
2460
by: mag31 | last post by:
Is there any way to find out if a particular .net function will throw an exception without first generating the exception? I am using structured exception handling i.e. try catch finally blocks...
11
1441
by: C# Learner | last post by:
What type of exception should I throw when my code detects that a connection has dropped (i.e. NetworkStream.Read() returns 0)? Should I just throw a SocketException or should I create my own...
6
2817
by: RepStat | last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally...
16
2143
by: Einar Høst | last post by:
Hi, I'm getting into the Trace-functionality in .NET, using it to provide some much-needed logging across dlls in the project we're working on. However, being a newbie, I'm wondering if some...
4
1838
by: Steve | last post by:
I have read a couple articles online, read my Jesse Liberty book but I am still confused as to just what the best practices are for using exceptions. I keep changing how I'm working with them and...
6
3368
by: JeffDotNet | last post by:
Writing to a registered source in the Application event log I have an asp.net framework 2.0 app that I created on a winxp machine and now I am deploying it to IIS6 on a win server2003 machine. ...
6
2030
by: Liming | last post by:
Hi, In a typical 3 tier model (view layer, busines layer and data access layer) where do you handle your exceptions? do you let it buble up all the way to the .aspx pages or do you handle it in...
0
7192
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7445
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4991
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.