C# Class Amazon.TraceListener.DynamoDBTraceListener

DynamoDBTraceListener is a custom TraceListener that logs events to a DynamoDB table. The listener can be configured through the application's .config file or by instantiating an instance of DynamoDBTraceListener and setting the Configuration property on the instance.

The target table must have a string hash key and a string range key. If the table does not exist the listener will create it during initialization with default read and write units set to 1 and 10, respectively, unless configured otherwise.

While DynamoDBTraceListener is running, it will write temporary log files into current directory. These log files will be deleted once the data is pushed to DynamoDB. The logs are pushed to DynamoDB under the following conditions: 1. Flush is called on the DynamoDBTraceListener 2. Close is called on the DynamoDBTraceListener 3. WritePeriod has elapsed since last write (If the listener is used with the SDK clients, Flush is invoked when the client is disposed.) If the application exits and there are still log files (in the event Flush is not invoked or the application terminates unexpectedly), these log files will be pushed to DynamoDB on the next execution of the application. Log files can also be flushed manually by creating an instance of DynamoDBTraceListener and using the FlushLog method on a particular log file.

Example of an app.config entry setting up the listener with all possible configurations specified: <system.diagnostics> <trace> <listeners> <add name="dynamo" type="Amazon.Logging.DynamoDBTraceListener, AWS.Extensions" AWSAccessKey="YOUR_ACCESS_KEY" AWSSecretKey="YOUR_SECRET_KEY" Region="us-west-2" Table="Logs" CreateIfNotExist="true" ReadCapacityUnits="1" WriteCapacityUnits="10" HashKey="Origin" RangeKey="Timestamp" MaxLength="10000" ExcludeAttributes="Callstack, Host" HashKeyFormat="{Host}-{EventType}-{ProcessId}" RangeKeyFormat="{Time}" WritePeriodMs="60000" LogFilesDir="C:\Logs" /> </listeners> </trace> </system.diagnostics>

Inheritance: System.Diagnostics.TraceListener
Exibir arquivo Open project: scopely/aws-sdk-net

Private Properties

Property Type Description
AppendDocument void
ComposeMessage string
CreateTable Amazon.DynamoDBv2.DocumentModel.Table
DeleteLogFile void
DisableListener void
EnsureWriter bool
ExpandVariables string
GetAttribute string
GetAttributeAsBool bool
GetAttributeAsInt int
GetConfigFromAttributes Configs
GetCurrentTimestamp System.DateTime
GetDocuments IEnumerable
GetNewLogFilePath string
Init void
IsLogFileEmpty bool
LimitLength string
Log void
TimedWriter void
WriteEventLogMessage void

Public Methods

Method Description
Close ( ) : void
DynamoDBTraceListener ( ) : System

Constructs an instance of the DynamoDBTraceListener.

DynamoDBTraceListener ( string name ) : System

Constructs a named instance of the DynamoDBTraceListener.

Flush ( ) : void
FlushLog ( string log ) : void

Flushes an existing log to DynamoDB, then deletes/empties the log file. This method can be invoked manually to flush left-over log files.

TraceData ( TraceEventCache eventCache, string source, TraceEventType eventType, int id ) : void
TraceData ( TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data ) : void
TraceEvent ( TraceEventCache eventCache, string source, TraceEventType eventType, int id ) : void
TraceEvent ( TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format ) : void
TraceTransfer ( TraceEventCache eventCache, string source, int id, string message, System.Guid relatedActivityId ) : void
Write ( string message ) : void
WriteLine ( string message ) : void

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Implements the Dispose pattern for the AmazonWebServiceClient

GetSupportedAttributes ( ) : string[]
WriteIndent ( ) : void

Private Methods

Method Description
AppendDocument ( Document doc ) : void
ComposeMessage ( object data ) : string
CreateTable ( ) : Table
DeleteLogFile ( string path ) : void
DisableListener ( string message ) : void
EnsureWriter ( ) : bool
ExpandVariables ( string value, Document doc ) : string
GetAttribute ( string name, string defaultValue = "" ) : string
GetAttributeAsBool ( string name, bool defaultValue = false ) : bool
GetAttributeAsInt ( string name, int defaultValue = -1 ) : int
GetConfigFromAttributes ( ) : Configs
GetCurrentTimestamp ( ) : System.DateTime
GetDocuments ( string path ) : IEnumerable
GetNewLogFilePath ( ) : string
Init ( ) : void
IsLogFileEmpty ( string path ) : bool
LimitLength ( string value ) : string
Log ( TraceEventCache eventCache, string source, TraceEventType eventType, int eventId ) : void
TimedWriter ( object sender, System e ) : void
WriteEventLogMessage ( string message, EventLogEntryType logEntryType ) : void

Method Details

Close() public method

public Close ( ) : void
return void

Dispose() protected method

Implements the Dispose pattern for the AmazonWebServiceClient
protected Dispose ( bool disposing ) : void
disposing bool Whether this object is being disposed via a call to Dispose /// or garbage collected.
return void

DynamoDBTraceListener() public method

Constructs an instance of the DynamoDBTraceListener.
public DynamoDBTraceListener ( ) : System
return System

DynamoDBTraceListener() public method

Constructs a named instance of the DynamoDBTraceListener.
public DynamoDBTraceListener ( string name ) : System
name string
return System

Flush() public method

public Flush ( ) : void
return void

FlushLog() public method

Flushes an existing log to DynamoDB, then deletes/empties the log file. This method can be invoked manually to flush left-over log files.
public FlushLog ( string log ) : void
log string
return void

GetSupportedAttributes() protected method

protected GetSupportedAttributes ( ) : string[]
return string[]

TraceData() public method

public TraceData ( TraceEventCache eventCache, string source, TraceEventType eventType, int id ) : void
eventCache System.Diagnostics.TraceEventCache
source string
eventType TraceEventType
id int
return void

TraceData() public method

public TraceData ( TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data ) : void
eventCache System.Diagnostics.TraceEventCache
source string
eventType TraceEventType
id int
data object
return void

TraceEvent() public method

public TraceEvent ( TraceEventCache eventCache, string source, TraceEventType eventType, int id ) : void
eventCache System.Diagnostics.TraceEventCache
source string
eventType TraceEventType
id int
return void

TraceEvent() public method

public TraceEvent ( TraceEventCache eventCache, string source, TraceEventType eventType, int id, string format ) : void
eventCache System.Diagnostics.TraceEventCache
source string
eventType TraceEventType
id int
format string
return void

TraceTransfer() public method

public TraceTransfer ( TraceEventCache eventCache, string source, int id, string message, System.Guid relatedActivityId ) : void
eventCache System.Diagnostics.TraceEventCache
source string
id int
message string
relatedActivityId System.Guid
return void

Write() public method

public Write ( string message ) : void
message string
return void

WriteIndent() protected method

protected WriteIndent ( ) : void
return void

WriteLine() public method

public WriteLine ( string message ) : void
message string
return void