Reputation: 1409
I think it is a standard question, but didn't find any generic one on SO.
Logging being core to debugging and other diagnostics warrants a good modular and scalable approach for enterprise apps. I am sure everyone here would have used such logging module at some time int heir coding careers.
So i would like to know best practices, best free tools/code used for logging in .NET apps.
Like whether to send log to file or DB ?
Should it be mostly trace-lines on exception catch and other imp. log points ? When all to use windows event logging ?
There is certain data like a jobID to identify the logs of that job's run, but problem is that this jobID is not available to every class, so logs from those classes are orphans without any jobID identifier. How to set such data (jobID) at the topmost method and then all logs emitted from all child methods get tagged with this data.
How to have multiple log files with ease, new file spawned on reaching size limit ?
How best to use system.diagnostics package ?
.. Any other thing i missed or any more helpful points about logging in general, pl add.
Upvotes: 0
Views: 593
Reputation: 35156
Use Enterprise Library for logging your exceptions, errors, traces, e.t.c. It can redirect your log entries to several sinks like Windows Event Log, File, Database, e.t.c.
Your code doesn't have to worry about target format and storage of log entry. You can configure all of that by modifying the config file.
The actual decision of where the logs go depends on the environment, data and its importance. If you want to be able to search and query the logs then DB is the option. If the sys admin uses Windows Event Log for viewing all logs then you can redirect your logs there.
Logging strategy varies from organization to organization and I believe your application shouldn't dictate it instead allow it to be configurable for which Logging Application Block or any other similar logging framework would be best choice.
Upvotes: 1