private static LogHeader ReadLogHeader(Stream stream, string filePath)
        {
            // ReSharper disable once UseObjectOrCollectionInitializer
            var header = new LogHeader();

            header.LogFilePath = filePath;
            // There are only 4 bytes for this in an aaLGX file.
            var headerLength = stream.GetInt(8);

            header.MsgCount          = (ulong)stream.GetInt(12);
            header.StartFileTime     = stream.GetFileTime(16);
            header.EndFileTime       = stream.GetFileTime(24);
            header.OffsetFirstRecord = stream.GetInt(32);
            header.OffsetLastRecord  = stream.GetInt(40);
            header.ComputerName      = GetComputerName(stream, headerLength);
            return(header);
        }
        private static LogRecord ReadLogRecord(Stream stream, int offset, int previousOffset, LogHeader header)
        {
            LOG.DebugFormat("offset: {0}", offset);
            // ReSharper disable once UseObjectOrCollectionInitializer
            var record = new LogRecord();

            record.RecordLength       = stream.GetInt(offset + 4);
            record.OffsetToPrevRecord = previousOffset;
            record.OffsetToNextRecord = checked (offset + record.RecordLength);

            stream.Seek(offset, SeekOrigin.Begin);
            var bytes = new byte[record.RecordLength];

            stream.Read(bytes, 0, record.RecordLength);

            record.MessageNumber = bytes.GetULong(16);
            record.SessionID     = bytes.GetSessionID(24);//  string.Format("{0}.{1}.{2}.{3}", bytes[27], bytes[26], bytes[25], bytes[24]);
            record.ProcessID     = (uint)bytes.GetInt(28);
            record.ThreadID      = (uint)bytes.GetInt(32);
            record.EventFileTime = bytes.GetFileTime(36);

            var position = 44;
            int length;

            record.LogFlag = bytes.GetString(position, out length);

            position        += length + 2;
            record.Component = bytes.GetString(position, out length);

            position      += length + 2;
            record.Message = bytes.GetString(position, out length);

            position          += length + 2;
            record.ProcessName = bytes.GetString(position, out length);
            return(record);
        }
예제 #3
0
        private static LogRecord ReadLogRecord(Stream stream, int offset, int previousOffset, LogHeader header)
        {
            LOG.DebugFormat("offset: {0}", offset);
            // ReSharper disable once UseObjectOrCollectionInitializer
            var record = new LogRecord();
            record.RecordLength = stream.GetInt(offset + 4);
            record.OffsetToPrevRecord = previousOffset;
            record.OffsetToNextRecord = checked(offset + record.RecordLength);

            stream.Seek(offset, SeekOrigin.Begin);
            var bytes = new byte[record.RecordLength];
            stream.Read(bytes, 0, record.RecordLength);

            record.MessageNumber = bytes.GetULong(16);
            record.SessionID = string.Format("{0}.{1}.{2}.{3}", bytes[27], bytes[26], bytes[25], bytes[24]);
            record.ProcessID = (uint)bytes.GetInt(28);
            record.ThreadID = (uint)bytes.GetInt(32);
            record.EventFileTime = bytes.GetFileTime(36);

            var position = 44;
            int length;
            record.LogFlag = bytes.GetString(position, out length);

            position += length + 2;
            record.Component = bytes.GetString(position, out length);

            position += length + 2;
            record.Message = bytes.GetString(position, out length);

            position += length + 2;
            record.ProcessName = bytes.GetString(position, out length);
            return record;
        }
예제 #4
0
        /// <summary>
        /// Read the log file header from the currently opened filestream
        /// </summary>
        /// <param name="logFileStream">Specific filestream to inspect and extract log header</param>        
        /// <returns>The log header for the file stream</returns>
        public LogHeader ReadLogHeader(FileStream logFileStream)
        {
            log.DebugFormat("logFileStream length - ", logFileStream.Length);

            int readResult;
            LogHeader localHeader = new LogHeader();
            int workingOffset = 0;
            byte[] byteArray = new byte[1];
            int fieldLength;

            try
            {

                // Set our file pointer to the beginning
                logFileStream.Seek((long)0, SeekOrigin.Begin);

                //Recreate the Byte Array with the appropriate size
                byteArray = new byte[12];

                //Get first 12 byteArray into the byte array.  The header length is in the last 4 byteArray
                readResult = logFileStream.Read(byteArray, 0, 12);

                // Get the last4 byteArray, starting at byte 8 to get the length of the header
                int headerLength = BitConverter.ToInt32(byteArray, 8);

                logFileStream.Seek((long)0, SeekOrigin.Begin);

                // Redim the byte array to the size of the header
                byteArray = new byte[checked(headerLength + 1)];

                //Now read in the entire header, considering the header length from above
                readResult = logFileStream.Read(byteArray, 0, headerLength);

                // Start to pick out the values
                // Start Message Number
                localHeader.StartMsgNumber = byteArray.GetULong(20);

                // Message Count
                localHeader.MsgCount = (ulong)byteArray.GetInt(28);

                // Start and End FileTime
                localHeader.StartFileTime = byteArray.GetFileTime(32);
                localHeader.EndFileTime = byteArray.GetFileTime(40);

                // Offset for the first lastRecordRead
                localHeader.OffsetFirstRecord = byteArray.GetInt(48);

                // Offset for the last lastRecordRead
                localHeader.OffsetLastRecord = byteArray.GetInt(52);

                // Computer Name
                workingOffset = 56;
                localHeader.ComputerName = byteArray.GetString(56, out fieldLength);

                // Session
                workingOffset += fieldLength + 2;
                localHeader.Session = byteArray.GetString(workingOffset, out fieldLength);

                // Previous File Name
                workingOffset += fieldLength + 2;
                localHeader.PrevFileName = byteArray.GetString(workingOffset, out fieldLength);

                //HostFQDN
                localHeader.HostFQDN = Fqdn.GetFqdn();

                localHeader.ReturnCode = new ReturnCodeStruct { Status = true, Message = "" };
            }
            catch (Exception ex)
            {
                this.ReturnCloseValue = this.CloseCurrentLogFile();
                localHeader.ReturnCode = new ReturnCodeStruct { Status = false, Message = ex.Message };
                log.Error(ex);
            }
            finally
            {
                // Set the log header to this locaheader we have calculated
                this.CurrentLogHeader = localHeader;
            }

            return this.CurrentLogHeader;
        }
예제 #5
0
 private static LogHeader ReadLogHeader(Stream stream, string filePath)
 {
     // ReSharper disable once UseObjectOrCollectionInitializer
     var header = new LogHeader();
     header.LogFilePath = filePath;
     // There are only 4 bytes for this in an aaLGX file.
     var headerLength = stream.GetInt(8);
     header.MsgCount = (ulong)stream.GetInt(12);
     header.StartFileTime = stream.GetFileTime(16);
     header.EndFileTime = stream.GetFileTime(24);
     header.OffsetFirstRecord = stream.GetInt(32);
     header.OffsetLastRecord = stream.GetInt(40);
     header.ComputerName = GetComputerName(stream, headerLength);
     return header;
 }
 public static string HeaderTSV()
 {
     return(LogHeader.Header('\t'));
 }
 public static string HeaderCSV()
 {
     return(LogHeader.Header(','));
 }
        public static string Header(char Delimiter = ',')
        {
            LogHeader lh = new LogHeader();

            return(lh.localHeader(Delimiter));
        }
예제 #9
0
 public static string Header(char Delimiter = ',')
 {
     LogHeader lh = new LogHeader();
     return lh.localHeader(Delimiter);
 }