C# Class SIL.Utils.Logger

Logs stuff to a file created in c:\Documents and Settings\Username\Local Settings\Temp\Companyname\Productname\Log.txt
This class also has a rudimentary implementation of IStream. The only really implemented method is IStream.Write, the other methods of this interface are no-ops or throw a NotImplementedException.
Inheritance: IFWDisposable, IStream
Exibir arquivo Open project: sillsdev/FieldWorks Class Usage Examples

Protected Properties

Property Type Description
m_out System.CodeDom.Compiler.IndentedTextWriter

Private Properties

Property Type Description
ConvertByteToChar char
Dispose void
GetLogText string
InitializeTextWriter void
Logger System
WriteEventInternal void

Public Methods

Method Description
CheckDisposed ( ) : void

Check to see if the object has been disposed. All public Properties and Methods should call this before doing anything else.

Clone ( IStream &ppstm ) : void

Creates a new stream object with its own seek pointer that references the same bytes as the original stream.

Commit ( int grfCommitFlags ) : void

Ensures that any changes made to a stream object that is open in transacted mode are reflected in the parent storage.

CopyTo ( IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten ) : void

Copies a specified number of bytes from the current seek pointer in the stream to the current seek pointer in another stream.

Dispose ( ) : void

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Must not be virtual.

Init ( string projectName ) : void

Creates the logger. The logging functions can't be used until this method is called.

LockRegion ( long libOffset, long cb, int dwLockType ) : void

Restricts access to a specified range of bytes in the stream.

Read ( byte pv, int cb, IntPtr pcbRead ) : void

Reads a specified number of bytes from the stream object into memory starting at the current seek pointer.

Revert ( ) : void

Discards all changes that have been made to a transacted stream since the last M:System.Runtime.InteropServices.ComTypes.IStream.Commit(System.Int32) call.

Seek ( long dlibMove, int dwOrigin, IntPtr plibNewPosition ) : void

Changes the seek pointer to a new location relative to the beginning of the stream, to the end of the stream, or to the current seek pointer.

SetSize ( long libNewSize ) : void

Changes the size of the stream object.

ShutDown ( ) : void

Shut down the logger. The logging functions can't be used after this method is called.

Stat ( System &pstatstg, int grfStatFlag ) : void

Retrieves the structure for this stream.

UnlockRegion ( long libOffset, long cb, int dwLockType ) : void

Removes the access restriction on a range of bytes previously restricted with the method.

Write ( byte pv, int cb, IntPtr pcbWritten ) : void

Writes a specified number of bytes into the stream object starting at the current seek pointer.

WriteError ( Exception e ) : void

Writes an exception and its stack trace to the log. This method will do nothing if Init() is not called first.

WriteError ( string msg, Exception e ) : void

Writes msg and an exception and its stack trace to the log. This method will do nothing if Init() is not called first.

WriteEvent ( string message ) : void

Writes an event to the logger. This method will do nothing if Init() is not called first.

Private Methods

Method Description
ConvertByteToChar ( byte b ) : char

Converts the byte to char.

Dispose ( bool disposing ) : void
GetLogText ( ) : string

Gets the log text.

InitializeTextWriter ( ) : void

Initializes (or reinitializes) the text writer.

Logger ( string logPrefix ) : System

Initializes a new instance of the Logger class.

WriteEventInternal ( string message ) : void

Writes the event to the logger.

Method Details

CheckDisposed() public method

Check to see if the object has been disposed. All public Properties and Methods should call this before doing anything else.
public CheckDisposed ( ) : void
return void

Clone() public method

Creates a new stream object with its own seek pointer that references the same bytes as the original stream.
public Clone ( IStream &ppstm ) : void
ppstm IStream When this method returns, contains the new stream object. /// This parameter is passed uninitialized.
return void

Commit() public method

Ensures that any changes made to a stream object that is open in transacted mode are reflected in the parent storage.
public Commit ( int grfCommitFlags ) : void
grfCommitFlags int A value that controls how the changes for the stream /// object are committed.
return void

CopyTo() public method

Copies a specified number of bytes from the current seek pointer in the stream to the current seek pointer in another stream.
public CopyTo ( IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten ) : void
pstm IStream A reference to the destination stream.
cb long The number of bytes to copy from the source stream.
pcbRead System.IntPtr On successful return, contains the actual number of bytes /// read from the source.
pcbWritten System.IntPtr On successful return, contains the actual number of bytes /// written to the destination.
return void

Dispose() public method

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Must not be virtual.
public Dispose ( ) : void
return void

Init() public static method

Creates the logger. The logging functions can't be used until this method is called.
public static Init ( string projectName ) : void
projectName string Name of the project that can be used (and certainly will /// be) to generate a unique log file name.
return void

LockRegion() public method

Restricts access to a specified range of bytes in the stream.
public LockRegion ( long libOffset, long cb, int dwLockType ) : void
libOffset long The byte offset for the beginning of the range.
cb long The length of the range, in bytes, to restrict.
dwLockType int The requested restrictions on accessing the range.
return void

Read() public method

Reads a specified number of bytes from the stream object into memory starting at the current seek pointer.
public Read ( byte pv, int cb, IntPtr pcbRead ) : void
pv byte When this method returns, contains the data read from the stream. /// This parameter is passed uninitialized.
cb int The number of bytes to read from the stream object.
pcbRead System.IntPtr A pointer to a ULONG variable that receives the actual number /// of bytes read from the stream object.
return void

Revert() public method

Discards all changes that have been made to a transacted stream since the last M:System.Runtime.InteropServices.ComTypes.IStream.Commit(System.Int32) call.
public Revert ( ) : void
return void

Seek() public method

Changes the seek pointer to a new location relative to the beginning of the stream, to the end of the stream, or to the current seek pointer.
public Seek ( long dlibMove, int dwOrigin, IntPtr plibNewPosition ) : void
dlibMove long The displacement to add to dwOrigin.
dwOrigin int The origin of the seek. The origin can be the beginning of /// the file, the current seek pointer, or the end of the file.
plibNewPosition System.IntPtr On successful return, contains the offset of the seek /// pointer from the beginning of the stream.
return void

SetSize() public method

Changes the size of the stream object.
public SetSize ( long libNewSize ) : void
libNewSize long The new size of the stream as a number of bytes.
return void

ShutDown() public static method

Shut down the logger. The logging functions can't be used after this method is called.
public static ShutDown ( ) : void
return void

Stat() public method

Retrieves the structure for this stream.
public Stat ( System &pstatstg, int grfStatFlag ) : void
pstatstg System When this method returns, contains a STATSTG structure that /// describes this stream object. This parameter is passed uninitialized.
grfStatFlag int Members in the STATSTG structure that this method does not /// return, thus saving some memory allocation operations.
return void

UnlockRegion() public method

Removes the access restriction on a range of bytes previously restricted with the method.
public UnlockRegion ( long libOffset, long cb, int dwLockType ) : void
libOffset long The byte offset for the beginning of the range.
cb long The length, in bytes, of the range to restrict.
dwLockType int The access restrictions previously placed on the range.
return void

Write() public method

Writes a specified number of bytes into the stream object starting at the current seek pointer.
public Write ( byte pv, int cb, IntPtr pcbWritten ) : void
pv byte The buffer to write this stream to.
cb int The number of bytes to write to the stream.
pcbWritten System.IntPtr On successful return, contains the actual number of bytes /// written to the stream object. If the caller sets this pointer to null, this method /// does not provide the actual number of bytes written.
return void

WriteError() public static method

Writes an exception and its stack trace to the log. This method will do nothing if Init() is not called first.
public static WriteError ( Exception e ) : void
e System.Exception
return void

WriteError() public static method

Writes msg and an exception and its stack trace to the log. This method will do nothing if Init() is not called first.
public static WriteError ( string msg, Exception e ) : void
msg string
e System.Exception
return void

WriteEvent() public static method

Writes an event to the logger. This method will do nothing if Init() is not called first.
public static WriteEvent ( string message ) : void
message string
return void

Property Details

m_out protected_oe property

protected IndentedTextWriter,System.CodeDom.Compiler m_out
return System.CodeDom.Compiler.IndentedTextWriter