Skip to content

Logging

Jeff Greene edited this page Jul 7, 2020 · 13 revisions

Harmony Core Logo

Logging

In its most basic form, logging for web services needs to have a few important pieces of information: some way to identify which request a log message was generated from, a time stamp stored in UTC, the severity of the log message (i.e., if it is a fatal error, error, warning, informational, or diagnostic), and finally the message text itself. It should be possible to quickly scan through any file-based log to collect all the messages that were relevant to a given user request. Logging must be thread safe and cannot impose a performance penalty in highly threaded environments.

The goal in implementing logging within Harmony Core has been to ensure that logging calls are as cheap as possible when the relevant logging level is disabled. This means that, as an overall philosophy, users of the library and the library itself should not be making expensive calls as part of the parameters to a logging call. Expensive calls can be hidden within Object.ToString(), where the cost is deferred until it has been decided to perform the logging operation.

Log Types

  • File - This is a streaming JSON file, which is human readable and machine readable. Since we include the session ID in the JSON object, it is very easy to choose a session ID and get all of the relevant messages for it.
  • Console - This very simple mechanism for logging makes development easier. The debugger doesn't need to be attached, it is fast, and you don't need to reload the log file constantly.
  • Event Log - This log type should only be used for very important errors. Not only is this the most expensive log entry type, it can quickly overwhelm an IT admin with Event Viewer entries.
  • Debug View - These log messages are only visible when a debugger or Debug Viewer is attached to the process.

Log Levels

Setting the environment variable ASPNETCORE_LOG_LEVEL to a number between 0 and 6 will result in decreasing levels of logging being printed to stdout. These logs will come from asp.net core internals. Setting HARMONY_CORE_LOG_LEVEL to a number between 0 and 6 will result in decreasing log levels for harmony core specific logs. When reporting diagnostic logs for a bug report, please set both of these environment variables to 0.

Clone this wiki locally