Click or drag to resize

LogFile Class

Represents a file that can be used for logging messages in real-time.
Inheritance Hierarchy

Namespace: GSF.IO
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.207-beta+1781b796b2aa7a54013a031eb432fe4ccee31867
Syntax

The LogFile type exposes the following members.

Constructors
 NameDescription
Public methodLogFile Initializes a new instance of the LogFile class.
Public methodLogFile(IContainer) Initializes a new instance of the LogFile class.
Top
Properties
 NameDescription
Protected propertyCanRaiseEventsGets a value indicating whether the component can raise an event.
(Inherited from Component)
Public propertyContainerGets the IContainer that contains the Component.
(Inherited from Component)
Protected propertyDesignModeGets a value that indicates whether the Component is currently in design mode.
(Inherited from Component)
Public propertyEnabled Gets or sets a boolean value that indicates whether the LogFile object is currently enabled.
Protected propertyEventsGets the list of event handlers that are attached to this Component.
(Inherited from Component)
Public propertyFileFullOperation Gets or sets the type of operation to be performed when the LogFile is full.
Public propertyFileName Gets or sets the name of the LogFile, including the file extension.
Public propertyFileSize Gets or sets the size of the LogFile in MB.
Public propertyFlushTimerInterval Gets or sets the number of seconds of inactivity before the LogFile automatically flushes the file stream.
Public propertyIsDisposed Gets a flag that indicates whether the object has been disposed.
Public propertyIsOpen Gets a boolean value that indicates whether the LogFile is open.
Public propertyLogFilesDuration Gets or sets the time duration, in hours, to save the LogFile .
Public propertyName Gets the unique identifier of the LogFile object.
Public propertyPersistSettings Gets or sets a boolean value that indicates whether the settings of LogFile object are to be saved to the config file.
Public propertySettingsCategory Gets or sets the category under which the settings of LogFile object are to be saved to the config file if the PersistSettings property is set to true.
Public propertySiteGets or sets the ISite of the Component.
(Inherited from Component)
Public propertyStatus Gets the descriptive status of the LogFile object.
Public propertyTextEncoding Gets or sets the Encoding to be used to encode the messages being logged.
Top
Methods
 NameDescription
Public methodBeginInit Performs necessary operations before the LogFile object properties are initialized.
Public methodClose Closes the LogFile if it is open.
Public methodClose(Boolean) Closes the LogFile if it is open.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject)
Public methodDisposeReleases all resources used by the Component.
(Inherited from Component)
Protected methodDispose(Boolean) Releases the unmanaged resources used by the LogFile object and optionally releases the managed resources.
(Overrides ComponentDispose(Boolean))
Public methodEndInit Performs necessary operations after the LogFile object properties are initialized.
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalizeReleases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection.
(Inherited from Component)
Public methodFlush Forces queued log entries to be written to the LogFile.
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject)
Protected methodGetServiceReturns an object that represents a service provided by the Component or by its Container.
(Inherited from Component)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodInitialize Initializes the LogFile object.
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject)
Public methodLoadSettings Loads saved settings for the LogFile object from the config file if the PersistSettings property is set to true.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject)
Protected methodOnFileFull Raises the FileFull event.
Protected methodOnLogException Raises the LogException event.
Public methodOpen Opens the LogFile for use if it is closed.
Public methodReadLines Reads text from the LogFile and returns a list of lines created by separating the text by the "newline" characters if and where present.
Public methodReadText Reads and returns the text from the LogFile.
Public methodSaveSettings Saves settings for the LogFile object to the config file if the PersistSettings property is set to true.
Public methodToStringReturns a String containing the name of the Component, if any. This method should not be overridden.
(Inherited from Component)
Public methodWrite Queues the text for writing to the LogFile.
Public methodWriteLine Queues the text for writing to the LogFile.
Public methodWriteTimestampedLine Queues the text for writing to the log file.
Top
Events
 NameDescription
Public eventDisposedOccurs when the component is disposed by a call to the Dispose method.
(Inherited from Component)
Public eventFileFull Occurs when the LogFile is full.
Public eventLogException Occurs when an Exception is encountered while writing entries to the LogFile.
Top
Fields
 NameDescription
Public fieldStatic memberDefaultFileFullOperation Specifies the default value for the FileFullOperation property.
Public fieldStatic memberDefaultFileName Specifies the default value for the FileName property.
Public fieldStatic memberDefaultFileSize Specifies the default value for the FileSize property.
Public fieldStatic memberDefaultFlushTimerInterval Specifies the default value for the FlushTimerInterval property.
Public fieldStatic memberDefaultLogFilesDuration Specifies the default value for the LogFilesDuration property.
Public fieldStatic memberDefaultPersistSettings Specifies the default value for the PersistSettings property.
Public fieldStatic memberDefaultSettingsCategory Specifies the default value for the SettingsCategory property.
Public fieldStatic memberMaxFileSize Specifies the maximum size for a LogFile.
Public fieldStatic memberMinFileSize Specifies the minimum size for a LogFile.
Top
Extension Methods
 NameDescription
Public Extension MethodGetEnumValueOrDefault Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Public Extension MethodGetEnumValueOrDefaultT Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Top
Example
This example shows how to use LogFile for logging messages:
C#
using System;
using GSF.IO;

class Program
{
    static void Main(string[] args)
    {
        LogFile log = new LogFile();
        log.Initialize();                       // Initialize the log file.
        log.Open();                             // Open the log file.
        log.WriteTimestampedLine("Test entry"); // Write message to the log file.
        log.Flush();                            // Flush message to the log file.
        log.Close();                            // Close the log file.

        Console.ReadLine();
    }
}
See Also