Joutsen Logging v0.5.0+22-gec3d058
Public Member Functions | Properties | List of all members
Joutsen.Logging.JsonFormatter Class Reference

A class that defines a Joutsen.Logging.IFormatter that formats log entries as JSON file records. More...

Public Member Functions

 JsonFormatter (bool prettyPrint=false)
 Creates a new instance of the formatter. More...
 
string Format (LogRecord record)
 Creates a JSON representation of the @paramref record. More...
 
string GetHeader (global::System.Text.Encoding encoding)
 Creates the opening bracket for the JSON array that will contain the log entries. More...
 
string GetTail ()
 Closes the JSON array containing the log entries. More...
 
string GetSeparator ()
 Creates a separator that is to be written between records. More...
 
- Public Member Functions inherited from Joutsen.Logging.Formatter
String Format (LogRecord record)
 Creates a formated string representation of the @paramref record which can be written. More...
 
String GetHeader (Encoding encoding)
 Creates the header that is to be written before the first record is written. More...
 
String GetTail ()
 Creates additional information that is written after the last record. More...
 
String GetSeparator ()
 Creates a separator that is to be written between records. More...
 

Properties

bool IsPrettyPrinted [get]
 Determines if the output of this formatter is pretty printed with indentation and line breaks. More...
 

Detailed Description

A class that defines a Joutsen.Logging.IFormatter that formats log entries as JSON file records.

Remarks
Creates a list of JSON objects containing the property of the record values as properties. The created records can be formatted to improve readability. If doing so, each level is indented with two spaces.
Since
0.3.0
Examples\n\ref FormatterExamples

Constructor & Destructor Documentation

◆ JsonFormatter()

Joutsen.Logging.JsonFormatter.JsonFormatter ( bool  prettyPrint = false)

Creates a new instance of the formatter.

Parameters
prettyPrintdetermines if the output should be pretty printed. Optional, default is false
Remarks
If @paramref prettyPrint is false all output will be in a single line, otherwise linebreaks and indentation will be added to the output. The pretty printed output is intended for human readability and should be avoided if the file can be post processed for readability because the not pretty printed version creates smaller logs.

Member Function Documentation

◆ Format()

string Joutsen.Logging.JsonFormatter.Format ( LogRecord  record)

Creates a JSON representation of the @paramref record.

@params record the record to create a formatted string from

Returns
a JSON-Sytem.String representation of the
Parameters
record

Implements Joutsen.Logging.Formatter.

◆ GetHeader()

string Joutsen.Logging.JsonFormatter.GetHeader ( global::System.Text.Encoding  encoding)

Creates the opening bracket for the JSON array that will contain the log entries.

Parameters
encodinginformation about the encoding that will be used to write log entries
Returns
a Sytem.String representing the opening bracket for the JSON array that will contain the log entries

◆ GetSeparator()

string Joutsen.Logging.JsonFormatter.GetSeparator ( )

Creates a separator that is to be written between records.

Returns
A separator string that is to be written between records. This is always a comma (,) and optional formatting characters.

Implements Joutsen.Logging.Formatter.

◆ GetTail()

string Joutsen.Logging.JsonFormatter.GetTail ( )

Closes the JSON array containing the log entries.

Returns
a Sytem.String representing the closing bracket of the JSON array

Implements Joutsen.Logging.Formatter.

Property Documentation

◆ IsPrettyPrinted

bool Joutsen.Logging.JsonFormatter.IsPrettyPrinted
get

Determines if the output of this formatter is pretty printed with indentation and line breaks.