DOes anyone have any good information with regards to when to log, I was thinking of logging an INFO type when i enter each c# method and recording another info when exiting..
Is this considered good or bad? Will i see a performance hit?
If i do record an INFO when i enter a method, the idea would be to record the method name, and all variable and values
Any idea how this can be done automatically without entering each value and name of method, i suppose i could use reflection but maybe i would see a slow down here?
If reflection would slow things down, maybe i could just use the "REFLECTION" bit when there program FAILS hence i can write the stacktrace, all vars, and values.
Any ideas or examples on this really appreciated
Thanks
You could use the AOP (Aspect oriented programming) style of logging for method-level logging.
There is a good framework called Log4PostSharp. It's a plugin to PostSharp which writes to Log4Net
It basically boils down to decorating your method with an attribute like this:
[Log(LogLevel.Info, "Doing something")]
public void CountCharacters() {
// do your logic here
}
I would use even lower level for this - TRACE (if it's available in log4net). DEBUG is good for logging particular occasions of something while TRACE is better used for dumping method calls, parameters and stuff like this. Definitely not INFO, which is more suitable for logging functional stuff on higher level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With