tags:

views:

94

answers:

2

Hi, We are developing a desktop application(visual basic 6.0).We have our own logging framework. What are good practices? When we have a web application, then we can control the level of logging. How to go about in a desktop app?

+2  A: 

Any answer needs to be considered based on your environment:

  • Do your business rules (or laws) require certain activities to be logged?
  • Is security an issue?
  • Do actions need to be traceable?
  • Is the size of the log file (or the amount of disk space) an issue?
  • Is your motivation to record activity, to debug, or both?

With those in mind:

  • Consider allowing the user to select the verbosity, or "logging level."
  • Log all program errors and significant user errors.
  • Log any activities that affect system configuration or operation.
  • Log the start and end of user sessions.
  • Log the start and end of the application.
  • Consider logging the first time a significant activity occurs.

Other suggestions:

  • Include timestamps, either in each log or at the beginning of a "group" of logs, as best appropriate for your application.
  • If you're logging to a file, consider rotating the log (i.e. closing one file and opening a new one) when it reaches a certain size or age.
  • If the application contains several modules, include the name of the module in each log.
  • If more than one person uses the application (shared computer?), log the user ID at the beginning of each session.
  • Assign log "levels" based on the severity (Error, Warning, Info, Debug). The syslog specification defines 7 "standard" levels that serve as a good reference.
  • Ask your customer what they expect to see in the log.
Adam Liss
A: 

An important feature to consider is to allow for adjustment of the log level dynamically at run time without requiring stopping and restarting the application (I've implemented this on *nix with a custom signal handler). This is a great help when debugging in the field.

Many times, a misbehaving application will behave fine when restarted. Dynamically tweakable log levels let you see whats going on before you release all your resources back to the OS.

dicroce