473,659 Members | 3,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Logging and exceptions, is it so hard?

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 logging and exceptions
handling for multiple threads server

Some question I have in mind are

1.Where is the best place in the component hierarchy to put logging?
(inside the lowest component or the highest one?)

2.Where is the best place in the component hierarchy to put logging of an
exception?
(since I always pass the inner exception,my rule of thumb is to log it
in the highest component in the hierarchy
without crossing thread boundaries)
3.When multiple thread writing to the same log file,performanc e can be
degraded,how to avoid this?
4.assuming the server write to a log file,I would like the admin program to
display it as it changes
what is a good way(I don't want to throw events to the user interface
when loging )
I know of course i can use mutex,events and MMF like visual studio and
dbmon do

and many more...

Thanks in adavnce.

----------------------------------------------------------------------------
-----------------------------------
I am writing in C# and using NSpring library for logging
Nov 16 '05 #1
4 1826
> 1.Where is the best place in the component hierarchy to put logging?
(inside the lowest component or the highest one?)
Where you think exceptions are most likely to occur!
An "exception" is just that - an exception to the normal circumstances. If
the circumstances are all normal and all is as you predicted, there should
never be an exception, not if you're program's written correctly! An
exception will most likely occur where there is most scope for user input,
therefore for users to input things wrong or do things in the wrong order.
But you might want to put one slightly higher than that just to be sure.
Or better still, you might want to put specific ones where you think they
will be likely to occur, and a generic 'catch all' one really high up that at
least alerts you that there's something you need to look further into, but
doesn't bring the program down.


2.Where is the best place in the component hierarchy to put logging of an
exception?
(since I always pass the inner exception,my rule of thumb is to log it
in the highest component in the hierarchy
without crossing thread boundaries)
See below.
3.When multiple thread writing to the same log file,performanc e can be
degraded,how to avoid this?
Have a synchronized queue, and then you can allow multiple threads to add
items to the queue. But then only have one thread removing them from the
queue, that writes the details to the log. You could isolate this
functionality into a component, which would answer your previous question.
I know of course i can use mutex,events and MMF like visual studio and
dbmon do
Thread synchronization in .NET is mightily simple...easier even than C++
I am ... using NSpring library for logging

Why? How come so many people think they need to use a 3rd party library for
this, that and the other?
You've already said you need to know how to synchronize logging, so this
warez solution obviously doesn't do that for you. The only other thing you
need to do is write to the event log... how hard can it be?


Nov 16 '05 #2
<snip>
I am ... using NSpring library for logging

Why? How come so many people think they need to use a 3rd party library
for
this, that and the other?


Two things. For one, most people don't have the time to write and debug
everything they need. That way lies insanity. And the other is that the
EventLog isn't the only option, NSpring offers quite a few different
mechanisms, from email to files to the event log to whatever. Combination
and layering of those services based on log level is usually the reason to
use a complicated logging environment.
Nov 16 '05 #3

"Where you think exceptions are most likely to occur!
An "exception" is just that - an exception to the normal circumstances. If
the circumstances are all normal and all is as you predicted, there should
never be an exception, not if you're program's written correctly! An
exception will most likely....."

If component A uses Component B, and B raise an exception I can log it
either in component B
or in Component A.so my question was what to take in consideration when
placing the log.
for example put it in B give me more information regarding the exception but
force component B to be familier
with the login technology
On the other hand if B used by several components and contain log code it
will be much harder to
find which component currently use B.

"Have a synchronized queue, and then you can allow multiple threads to add
items to the queue. But then only have one thread removing them from the
queue, that writes the details to the log. You could isolate this
functionality into a component, which would answer your previous question."

Ok it is a good idea(basically what you say that synchronized queue won't
hart performance like a synchronized access to a file?)

"Why? How come so many people think they need to use a 3rd party library for
this, that and the other?"

Time constraints.

Thanks.


Nov 16 '05 #4
Hi Julia, I'm using Apache's log4net
(http://logging.apache.org/log4net/). I suggets you to visit their
site.
Nov 16 '05 #5

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

Similar topics

6
9960
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?
16
2161
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 more experienced loggers can provide me with some ideas as to how to log in a simple yet flexible manner. For instance, I'd like the code to be as uncluttered as possible by Trace statements. As an example of basic logging functionality, I've come...
0
1353
by: rshekhtm | last post by:
Hi everyone, I would like to get your opinion on a technique I came up with when faced with the problem of redundant code in every web method (authentication, logging, exception handling). Normally, my web methods would look something like this: public ReturnType GetSomeData(SomeType param1) {
4
3394
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 printed' .... Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.5/lib/ python2.5/logging/__init__.py", line 744, in emit
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8747
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...
0
8627
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6179
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
4175
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...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
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
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.