473,394 Members | 1,821 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,394 software developers and data experts.

best way to log exceptions

Hi,

I have a class called Loger that has only a static method:

public class Logger
{
public static void LogException (Exception e)
{
//code to write the exception into a text file...
}
}

I have, for other hand a group of classes that does some operations and i
would like to log every exception inside each class.

Its a good way to call this static method every time the code execute a
catch statement?

for instance:

try
{
//do something
}
catch (Exception e)
{
Logger.LogException(e);
}

What do you think about it?
--
Thanks a lot
Regards.
Josema
Nov 17 '05 #1
3 10725
Have you looked at http://logging.apache.org/log4net/

Nov 17 '05 #2
Hi,

It's simple and useful way, I do it in more than one project , you could
select to either write it to a file ( as you do ) or to an Event Log .

Also take a look into the Exception app block from MS:

http://msdn.microsoft.com/library/de.../html/ehab.asp

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Josema" <Je******@ocu.org> wrote in message
news:08**********************************@microsof t.com...
Hi,

I have a class called Loger that has only a static method:

public class Logger
{
public static void LogException (Exception e)
{
//code to write the exception into a text file...
}
}

I have, for other hand a group of classes that does some operations and i
would like to log every exception inside each class.

Its a good way to call this static method every time the code execute a
catch statement?

for instance:

try
{
//do something
}
catch (Exception e)
{
Logger.LogException(e);
}

What do you think about it?
--
Thanks a lot
Regards.
Josema

Nov 17 '05 #3
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:u%***************@tk2msftngp13.phx.gbl...
Also take a look into the Exception app block from MS:

http://msdn.microsoft.com/library/de.../html/ehab.asp


I personally think the MS app blocks are junk. There is just too much code
in there and it can't all be useful. Most times the easy and transparent
approach is best. If you can achieve in one or two lines what someone else
has done in 10000 lines, consider the possiblity that your way is best.
Nov 17 '05 #4

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

Similar topics

9
by: Mark Twombley | last post by:
Hi, I'm just getting back into C++ and had a question about the best practice for assigning error numbers. I have been working in VB for sometime now and there you would start assigning error...
4
by: Johannes Hansen | last post by:
What are the best practice on handling an exception caused by a Dispose method when its called from inside a loop? Wrap the entire loop in a try-catch or do the try-catch on each iteration to get...
8
by: SStory | last post by:
When I right a class, I am wondering what are the best practices for error handling? Do I try..catch and trap the error and if so what do I do with it? Because most likely the class user will...
2
by: Petr Jakes | last post by:
I am a little bit confused by all possibilities for exceptions handling in Python (probably because I am not skilled enough??) I did try to search trough this list and reading Python tutorial about...
9
by: Mr Flibble | last post by:
Hi all, happy Friday! (certainly Friday is a day worth celebrating). I have a question on try/catch design (an exciting Friday topic for sure): I can either put a try/catch block in every...
17
by: 2005 | last post by:
Hi In C++, are the following considered best practices or not? - passing aguments to functions (ie functions do not take any arguments ) - returning values using return statement Anything...
24
by: Earl | last post by:
I have all of my data operations in a separate library, so I'm looking for what might be termed "best practices" on a return type from those classes. For example, let's say I send an update from...
13
by: vizcayno | last post by:
Hello: Need your help in the "correct" definition of the next function. If necessary, I would like to know about a web site or documentation that tells me about best practices in defining...
5
by: =?Utf-8?B?QmlsbHk=?= | last post by:
asp.net 2.0 vs2005 What is best practice for exception handling on a website in vs2005? I was going to catch errors in application on_error event, log them to the event log, then send users to...
10
by: Brendan Miller | last post by:
What would heavy python unit testers say is the best framework? I've seen a few mentions that maybe the built in unittest framework isn't that great. I've heard a couple of good things about...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.