Wiki Navigation
- Loading...
Overview
In MediaPortal 2, log output can be written by using our logging service (service interface ILogger ). That service is automatically installed by the main MP2 applications and provides a simple logging interface.
Details
Supported features are:
- Log levels (Critical, Error, Warning, Information, Debug)
- Logging of exceptions
- Logging to the console
- Logging to a file
- Support of multiple opened log files from different MP2 applications at the same logfile path
- Logging to multiple loggers at the same time
What should be logged and how
Logging has multiple jobs:
- Error debugging
- Tracing a user's action to reproduce an error
There are some elementary guidelines which should be followed when a log output is written from code
Write enough information into the log message
This sounds trivial but is sometimes done wrong. When logging an exception in a catch block, please write enough , sensible and informative information into the message. Avoid writing useless messages:
Bad log message:
An exception has occured
Good log message:
Error unmarshalling data from IR service 'localhost'
The exception object should be passed to the logger if it brings more information about the error:
try { ... } catch (XxxException e) { ServiceRegistration.Get<ILogger>().Warn("Error unmarshalling data from IR service '{0}'", e, irServiceHost); }
Write actual data into the log message
To make log message helpful, all necessary data should be provided to understand what happened. For example, a log message can be made much more useful by giving the user more information about the data which caused the exception.
Bad log message:
Illegal character encountered
Better you tell the reader WHICH character was illegal at what position:
Message with more information:
Illegal character 'X' (#88) encountered in document at position 7
Quote logged data
When actual data is logged, please quote strings. A log message
Illegal user Mr. X
is harder to read than
Illegal user 'Mr. X'
Furthermore, if a string is empty or contains leading or trailing spaces, it is very hard to find the problem in a message like
// Do you see the trailing spaces? Illegal user
or
// Do you see the trailing space? Illegal user Mr. X
Better would be
Illegal user ' '
or
Illegal user 'Mr. X '
where the reader can see that maybe a space is the problem.
This page has no comments.