Using Loggers in Your Project Code

The following sections describe how to set up logging in JIA projects. The logging capabilities of JIA collect all necessary data and and provide all the tools required for the JIA support team to investigate and reproduce a problem without the need to work on the specific environment in which the problem occurred.

tog_minusUsing Loggers in C# Code

Developers working with C# code should use log4net as the logging tool. As the code uses a private logger for each class, the class should appear as part of the log line in the log files. The logger name is retrieved from the class type, which allows the configuration to have more control over which classes should be reported to the logs, and at what level they should be reported.

To properly set up logging in the user code, in each class, define a static logger that will be used only in the scope of the specific class. The logger should be defined as follows:

private static ILog logger = LogManager.GetLogger(typeof(ServiceBase));

To use the logger, call one of the log level methods of the logger. For example:

logger.Debug("Some log message");

For more assistance in logging configuration, refer to the log4net documentation.

Note: The previously used DefaultLogger object is now obsolete, although backward compatibility is supported.

tog_minusLogging in Java (versions 1.5 and above)

When working with Java, the log4j library is used, so that logging is written to both the console and the files. If the hosting Java application also uses log4j, the logging configuration of the hosting application is used (i.e., the JIA logs are located in the log files of the host application).

The configuration of JIA logging with log4j is set by the following parameter:

-Dlog4j.configuration="jia.log4j.properties"

To inject the JIA logging code into the host application (when the host application does not use log4j), verify that the parameter is included in the runtime configuration parameters. For an example, refer to Using the RunJavaPP Batch File.
When the host application uses log4j, remove the parameter from the runtime configuration parameters.

For more information about log4j configuration, click here.