473,396 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Logging and exceptions

Hi all,

I'm wondering about when the best time to log an exception would be
(such as to the event log, or a text file, etc.)

If you have a multi tier application, and one of the lower layers
throws an exception, should that layer log the exception and bubble it
up (causing all higher levels to also log)? Or should the exception be
allowed to move up to the application and the application is solely
responsible for logging?

What has worked well for you?

Thanks
andy

Nov 17 '05 #1
6 1359
Andy,

Personally, if there is an exception, I like to bubble it up through the
layers (I think you are in agreement on this). As for when to log, I would
think that when a call traverses layers, you should log the exception, and
then allow it to bubble up. This would require you to place catches at each
point where your layers are accessed, which can be tedious.

However, if you are using a technology where the exception is
automatically handled for you (like remoting, where if there is an
exception, that exception will be thrown on the client side), it might not
be such a bad idea to let the client handle this kind of stuff.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andy" <aj********@capcitypress.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Hi all,

I'm wondering about when the best time to log an exception would be
(such as to the event log, or a text file, etc.)

If you have a multi tier application, and one of the lower layers
throws an exception, should that layer log the exception and bubble it
up (causing all higher levels to also log)? Or should the exception be
allowed to move up to the application and the application is solely
responsible for logging?

What has worked well for you?

Thanks
andy

Nov 17 '05 #2
Nicholas,

Thanks for the input.

Yes, I am definatly going to bubble up the exceptions. As each
exception is caught by a layer, it wraps it in an Exception declared in
that layer. (I believe this is what is commonly done as well, but I'd
appreciate comments on this practice as well).

Andy

Nov 17 '05 #3
Andy,

This is pretty much what other technologies do. For example, if an
exception is thrown on the server, then that exception is caught, and then
placed in a RemotingException (the original exception is exposed through the
InnerException property). This way, if there is a problem in the remoting
itself, you can detect it through any exception except a RemotingException.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andy" <aj********@capcitypress.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Nicholas,

Thanks for the input.

Yes, I am definatly going to bubble up the exceptions. As each
exception is caught by a layer, it wraps it in an Exception declared in
that layer. (I believe this is what is commonly done as well, but I'd
appreciate comments on this practice as well).

Andy

Nov 17 '05 #4
Speaking of logging,

Hello, I'm new to C#. I'm using Visual Studio and IIS, developing and
running web projects with C#. In this environment, when I execute

Console.writeln("Message");

the message does not appear in any window of my Vis. Studio that I know of,
and does not log anywhere that I know of.

How can I configure IIS to log these Console.writelns to a specific place
and/or configure visual studio to write them to a console window?

Thanks for any help,

Andrew

"Nicholas Paldino [.NET/C# MVP]" wrote:
Andy,

This is pretty much what other technologies do. For example, if an
exception is thrown on the server, then that exception is caught, and then
placed in a RemotingException (the original exception is exposed through the
InnerException property). This way, if there is a problem in the remoting
itself, you can detect it through any exception except a RemotingException.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andy" <aj********@capcitypress.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Nicholas,

Thanks for the input.

Yes, I am definatly going to bubble up the exceptions. As each
exception is caught by a layer, it wraps it in an Exception declared in
that layer. (I believe this is what is commonly done as well, but I'd
appreciate comments on this practice as well).

Andy


Nov 17 '05 #5
Oasis,

You shouldn't be using Console.WriteLine for ASP.NET applications.
Those messages are just going to be lost.

If you need to log certain things, you can attach listeners to the Trace
object (there are static methods to do this, and the class is in the
System.Diagnostics namespace). This will allow you to place messages in
your program to be written to the listeners. You can have the listeners
write output to a log file, a database, or whatever you wish. Additionally,
you can configure this without having to write any code (it would be
configured through the web.config file).

Take a look at the TraceListener class documentation for how configure
the trace listeners, as well as a list of pre-defined trace listeners.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Oasis" <Oa***@discussions.microsoft.com> wrote in message
news:67**********************************@microsof t.com...
Speaking of logging,

Hello, I'm new to C#. I'm using Visual Studio and IIS, developing and
running web projects with C#. In this environment, when I execute

Console.writeln("Message");

the message does not appear in any window of my Vis. Studio that I know
of,
and does not log anywhere that I know of.

How can I configure IIS to log these Console.writelns to a specific place
and/or configure visual studio to write them to a console window?

Thanks for any help,

Andrew

"Nicholas Paldino [.NET/C# MVP]" wrote:
Andy,

This is pretty much what other technologies do. For example, if an
exception is thrown on the server, then that exception is caught, and
then
placed in a RemotingException (the original exception is exposed through
the
InnerException property). This way, if there is a problem in the
remoting
itself, you can detect it through any exception except a
RemotingException.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andy" <aj********@capcitypress.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
> Nicholas,
>
> Thanks for the input.
>
> Yes, I am definatly going to bubble up the exceptions. As each
> exception is caught by a layer, it wraps it in an Exception declared in
> that layer. (I believe this is what is commonly done as well, but I'd
> appreciate comments on this practice as well).
>
> Andy
>


Nov 17 '05 #6
Nicholas,
thank you very much for pointing me in the right direction!

oasis

"Nicholas Paldino [.NET/C# MVP]" wrote:
Oasis,

You shouldn't be using Console.WriteLine for ASP.NET applications.
Those messages are just going to be lost.

If you need to log certain things, you can attach listeners to the Trace
object (there are static methods to do this, and the class is in the
System.Diagnostics namespace). This will allow you to place messages in
your program to be written to the listeners. You can have the listeners
write output to a log file, a database, or whatever you wish. Additionally,
you can configure this without having to write any code (it would be
configured through the web.config file).

Take a look at the TraceListener class documentation for how configure
the trace listeners, as well as a list of pre-defined trace listeners.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Oasis" <Oa***@discussions.microsoft.com> wrote in message
news:67**********************************@microsof t.com...
Speaking of logging,

Hello, I'm new to C#. I'm using Visual Studio and IIS, developing and
running web projects with C#. In this environment, when I execute

Console.writeln("Message");

the message does not appear in any window of my Vis. Studio that I know
of,
and does not log anywhere that I know of.

How can I configure IIS to log these Console.writelns to a specific place
and/or configure visual studio to write them to a console window?

Thanks for any help,

Andrew

"Nicholas Paldino [.NET/C# MVP]" wrote:
Andy,

This is pretty much what other technologies do. For example, if an
exception is thrown on the server, then that exception is caught, and
then
placed in a RemotingException (the original exception is exposed through
the
InnerException property). This way, if there is a problem in the
remoting
itself, you can detect it through any exception except a
RemotingException.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andy" <aj********@capcitypress.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
> Nicholas,
>
> Thanks for the input.
>
> Yes, I am definatly going to bubble up the exceptions. As each
> exception is caught by a layer, it wraps it in an Exception declared in
> that layer. (I believe this is what is commonly done as well, but I'd
> appreciate comments on this practice as well).
>
> Andy
>


Nov 17 '05 #7

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

Similar topics

0
by: Jeremy Fincher | last post by:
I've just converted my application to use the logging module for its logging needs (it's quite excellent, actually :)). One thing I still have to resolve, though: in many places in my application,...
0
by: Ayende Rahien | last post by:
I'm more than a little bit confused regarding logging & exception handling. To start with, I want to use a single point in my applications for logging and possibly for exception handling. My...
6
by: Kevin Jackson | last post by:
Let's say we log exceptions to the windows application event log using the Exception Management Application Block. Is there a pattern that can be used so the exception is logged only once and not...
16
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
by: Julia | last post by:
Hi, So my server is complete,I have all the code and libraries which I need but now I want to add exception management and logging capabilities I would like you to suggest a good book about...
17
by: Cramer | last post by:
I plan to implement an exception logging feature in an ASP.NET Web application that writes encountered exceptions to disk. The exception data will be stored as XML. I am planning on having each...
4
by: Alexandru Mosoi | last post by:
why doesn't logging throw any exception when it should? how do I configure logging to throw exceptions? .... logging.fatal('asdf %d', '123') .... except: .... print 'this line is never...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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,...

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.