473,796 Members | 2,482 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception Handling Question: Event Logging

ETL
Hi,
I think this question has an easy answer but I can't seem to find
anything online that lists best practices for my problem.

I have a C# app that uses an exception handling tree similar to the
following.

Try
{
blah blah blah....
}
catch(Unauthori zedAccessExcept ion noAuth){}
catch(IndexOutO fRangeException ){}
catch(Exception Ex){}
finally{}

I want to log an event on my server if any of the following exceptions
are thrown. My server logging methog looks like this:

LoggingManager. LogServerEvent( Exception.Messa ge.ToString());

I can add this method to each catch clause and it alogs the event fine.
I'd like to optimize my code so that this logging method is only in one
place. It seems silly to put it in all the catch clauses. Basically, if
ANY exceptions was raised, log it.

Any suggestions?

Thanks

Eric

Nov 17 '05 #1
2 1510
I think you'll have to catch it in each catch block. unless there's a
way to trigger an event on any exception, then use that event to log the
exception, you'll have to put it in each place.

that's my admittedly limited experience, anyway.

--
jeremiah();

ETL wrote:
Hi,
I think this question has an easy answer but I can't seem to find
anything online that lists best practices for my problem.

I have a C# app that uses an exception handling tree similar to the
following.

Try
{
blah blah blah....
}
catch(Unauthori zedAccessExcept ion noAuth){}
catch(IndexOutO fRangeException ){}
catch(Exception Ex){}
finally{}

I want to log an event on my server if any of the following exceptions
are thrown. My server logging methog looks like this:

LoggingManager. LogServerEvent( Exception.Messa ge.ToString());

I can add this method to each catch clause and it alogs the event fine.
I'd like to optimize my code so that this logging method is only in one
place. It seems silly to put it in all the catch clauses. Basically, if
ANY exceptions was raised, log it.

Any suggestions?

Thanks

Eric

Nov 17 '05 #2
Hi Eric,

You did not give all the details of the blah blah part of your code,
now based on the limited information :
- why do you have to catch three types of exceptions ? can you
refactor your blah blah part of the code ? it seems to me that this
method has different roles, granting access, getting elements from an
array, etc
- it is sufficient to catch Exception and log the Message, you will
have the same functionality as you have know (Exception is the base of
the other exceptions)
- check the exception handling on
http://www.microsoft.com/downloads/d...displaylang=en

success,
Bart

http://www.xenopz.com

Nov 17 '05 #3

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

Similar topics

6
9969
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 everytime up through the call chain? Is there anything a caller can key off of to check to see if it should also log the exception?
44
4231
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level user tasks should always be included in a try/catch block that actually handles any exceptions that occur (log the exception, display a message box, etc.). 2. Low-level operations that are used to carry out the high level tasks
4
1847
by: sm | last post by:
Hi, I have a couple of questions with regards to handling errors and exceptions. 1. If I use On Error goto Errhandler ... Errhandler:
1
4143
by: David Herbst | last post by:
Enterprise Library Jan 2006 with Visual Studio 2005 on Windows 2000 Server sp4. My custom exception formatter fails with a "Unable to handle exception: 'LoggingExceptionHandler'." exception. When I attached the debugger to the process and stepped into the code it executed without error. In both cases I was running a Debug build, the only difference in the case that works is that I attached the debugger to the same exact binaries....
0
9528
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10173
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7547
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2925
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.