#pragma warning restore 1591 //------------------------------------------------------------------------------ // // Method: Dispose // //------------------------------------------------------------------------------ /// <summary> /// Provides a method to free unmanaged resources used by this class. /// </summary> /// <param name="disposing">Whether the method is being called as part of an explicit Dispose routine, and hence whether managed resources should also be freed.</param> protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { // Free other state (managed objects). } // Free your own state (unmanaged objects). if (loggerImplementation != null) { loggerImplementation.Dispose(); } // Set large fields to null. loggerImplementation = null; disposed = true; } }
//------------------------------------------------------------------------------ // // Method: FileMetricLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.FileMetricLogger class. /// </summary> /// <param name="separatorCharacter">The character to use to separate fields (e.g. date/time stamp, metric name) in the file.</param> /// <param name="filePath">The full path of the file to write the metric events to.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> public FileMetricLogger(char separatorCharacter, string filePath, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking) { loggerImplementation = new FileMetricLoggerImplementation(separatorCharacter, filePath, bufferProcessingStrategy, intervalMetricChecking); }
//------------------------------------------------------------------------------ // // Method: FileMetricLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.FileMetricLogger class. /// </summary> /// <remarks>This constructor defaults to using the LoopingWorkerThreadBufferProcessor as the buffer processing strategy, and is maintained for backwards compatibility.</remarks> /// <param name="separatorCharacter">The character to use to separate fields (e.g. date/time stamp, metric name) in the file.</param> /// <param name="filePath">The full path of the file to write the metric events to.</param> /// <param name="dequeueOperationLoopInterval">The time to wait (in milliseconds) between iterations of the worker thread which dequeues metric events and writes them to the file.</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="appendToFile">Whether to append to an existing file (if it exists) or overwrite. A value of true causes appending.</param> /// <param name="fileEncoding">The character encoding to use in the file.</param> public FileMetricLogger(char separatorCharacter, string filePath, int dequeueOperationLoopInterval, bool intervalMetricChecking, bool appendToFile, Encoding fileEncoding) { loggerImplementation = new FileMetricLoggerImplementation(separatorCharacter, filePath, new LoopingWorkerThreadBufferProcessor(dequeueOperationLoopInterval, false), intervalMetricChecking, appendToFile, fileEncoding); }
//------------------------------------------------------------------------------ // // Method: FileMetricLogger (constructor) // //------------------------------------------------------------------------------ /// <summary> /// Initialises a new instance of the ApplicationMetrics.FileMetricLogger class. Note this is an additional constructor to facilitate unit tests, and should not be used to instantiate the class under normal conditions. /// </summary> /// <param name="separatorCharacter">The character to use to separate fields (e.g. date/time stamp, metric name) in the file.</param> /// <param name="bufferProcessingStrategy">Object which implements a processing strategy for the buffers (queues).</param> /// <param name="intervalMetricChecking">Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()).</param> /// <param name="streamWriter">A test (mock) stream writer.</param> /// <param name="dateTime">A test (mock) DateTime object.</param> /// <param name="exceptionHandler">A test (mock) exception handler object.</param> public FileMetricLogger(char separatorCharacter, IBufferProcessingStrategy bufferProcessingStrategy, bool intervalMetricChecking, IStreamWriter streamWriter, IDateTime dateTime, IExceptionHandler exceptionHandler) { loggerImplementation = new FileMetricLoggerImplementation(separatorCharacter, bufferProcessingStrategy, intervalMetricChecking, streamWriter, dateTime, exceptionHandler); }