protected override void LogRecord(string message, LogRecordType logRecordType) { string logRecord = base.GetLogRecord(message, logRecordType); _logFileWriter.WriteLine(logRecord); _logFileWriter.Flush(); }
private List <LogRecord> getPagedRecords(int?page, LogRecordType recType, out int maxPageNumber) { maxPageNumber = 0; using (zcrlDbContext = new ZcrlContext()) { List <LogRecord> allRecords; allRecords = (from p in zcrlDbContext.LogJournal where (p.RecordType == recType) orderby p.СreatedDate descending select p).ToList(); maxPageNumber = (int)(Math.Ceiling(allRecords.Count() / 50.0)); if (!page.HasValue) { return(allRecords.Take(50).ToList()); } if ((page.Value < 1) || (page.Value > maxPageNumber)) { return(null); } else { return(allRecords.Skip(((page.Value - 1) * 10)).Take(50).ToList()); } } }
public static void AddUnionPalaceEvent(GameClient client, LogRecordType logRecordType, params object[] args) { try { if (!GameManager.FlagEnableUnionPalaceLog) { return; } string eventMsg = string.Format("{0}\t{1}\t{2}\t{3}", (int)logRecordType, client.ServerId, client.strUserID, client.ClientData.RoleID ); foreach (var arg in args) { eventMsg += "\t" + arg; } SystemRoleEvents[(int)RoleEvent.UnionPalace].AddEvent(eventMsg, EventLevels.Important); } catch (System.Exception ex) { LogManager.WriteLog(LogTypes.Exception, ex.ToString()); } }
public Record(LogRecordType logRecordType) { LogRecordType = logRecordType; Checksum = 0; Length = 0; Data = ReadOnlySpan <byte> .Empty; }
/// <summary>Gets name of the LogRecordType</summary> public static string RecordTypeToString(LogRecordType type) { switch (type) { case LogRecordType.Engine: return("Engine"); case LogRecordType.Error: return("Error"); case LogRecordType.Input: return("Input"); case LogRecordType.Message: return("Message"); case LogRecordType.Warning: return("Warning"); case LogRecordType.Commander: return("Commander"); case LogRecordType.NetworkCommander: return("NetComm"); default: throw new System.Exception("RecordTypeToString: " + type.ToString() + " is unexpected."); } }
/// <summary>Converts a log message type to a corresponding color.</summary> public static Color RecordTypeToColor(LogRecordType type) { switch (type) { case LogRecordType.Commander: return(Color.cyan); case LogRecordType.Engine: return(Color.green); case LogRecordType.Error: return(Color.red); case LogRecordType.Input: return(Color.yellow); case LogRecordType.Message: return(Color.white); case LogRecordType.Warning: return(Color.red); case LogRecordType.NetworkCommander: return(new Color(1, 0.5f, 0)); default: throw new System.Exception("RecordTypeToColor: " + type.ToString() + " is unexpected."); } }
protected LogRecord(LogRecordType recordType, byte version, long logPosition) { Ensure.Nonnegative(logPosition, "logPosition"); RecordType = recordType; Version = version; LogPosition = logPosition; }
private static LogRecord ReadFromOperationData(OperationData operationData) { LogRecord record; long lsn; const ulong RecordPosition = InvalidRecordPosition; LogRecordType recordType; var index = -1; using (var reader = new BinaryReader(IncrementIndexAndGetMemoryStreamAt(operationData, ref index))) { // Logical metadata section. var startingPosition = reader.BaseStream.Position; var sizeOfSection = reader.ReadInt32(); var endPosition = startingPosition + sizeOfSection; // Logical metadata read. recordType = (LogRecordType)reader.ReadUInt32(); lsn = reader.ReadInt64(); // Jump to the end of the section ignoring fields that are not understood. Utility.Assert(endPosition >= reader.BaseStream.Position, "Could not have read more than section size."); reader.BaseStream.Position = endPosition; } switch (recordType) { case LogRecordType.BeginTransaction: record = new BeginTransactionOperationLogRecord(recordType, RecordPosition, lsn); break; case LogRecordType.Operation: record = new OperationLogRecord(recordType, RecordPosition, lsn); break; case LogRecordType.EndTransaction: record = new EndTransactionLogRecord(recordType, RecordPosition, lsn); break; case LogRecordType.Barrier: record = new BarrierLogRecord(recordType, RecordPosition, lsn); break; case LogRecordType.UpdateEpoch: record = new UpdateEpochLogRecord(recordType, RecordPosition, lsn); break; case LogRecordType.Backup: record = new BackupLogRecord(recordType, RecordPosition, lsn); break; default: Utility.CodingError( "Unexpected record type received during replication/copy processing {0}", recordType); return(null); } record.ReadLogical(operationData, ref index); return(record); }
public LogRecord(LogRecordSource source, LogRecordType type, string message) { Date = DateTime.Now; Source = source; Type = type; Message = message; }
/// <summary>Record a log message.</summary> public LogRecord(string message, LogRecordType type = LogRecordType.Message, float time = 0) { this.Message = message; this.Type = type; this.Color = RecordTypeToColor(type); this.Time = time; }
internal BeginCheckpointLogRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { Utility.Assert( recordType == LogRecordType.BeginCheckpoint, "Record type is expected to be begin checkpoint but the record type is : {0}", recordType); this.IsFirstCheckpointOnFullCopy = false; this.progressVector = null; this.earliestPendingTransactionOffset = LogicalLogRecord.InvalidLogicalRecordOffset; this.earliestPendingTransaction = BeginTransactionOperationLogRecord.InvalidBeginTransactionLogRecord; this.checkpointState = CheckpointState.Invalid; this.lastStableLsn = LogicalSequenceNumber.InvalidLsn; this.epoch = LogicalSequenceNumber.InvalidEpoch; // Initializes the backup information to invalid. this.backupId = BackupLogRecord.InvalidBackupId; this.highestBackedUpEpoch = new Epoch( LogicalSequenceNumber.InvalidLsn.LSN, LogicalSequenceNumber.InvalidLsn.LSN); this.highestBackedUpLsn = LogicalSequenceNumber.InvalidLsn; // Uint.MaxValue is used to indicate invalid. 4,294,967,295 log records, 4.294967295 TB. this.backupLogRecordCount = uint.MaxValue; this.backupLogSize = uint.MaxValue; this.earliestPendingTransactionInvalidated = 0; this.lastPeriodicCheckpointTimeTicks = 0; this.lastPeriodicTruncationTimeTicks = 0; }
internal EndCheckpointLogRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { Utility.Assert(recordType == LogRecordType.EndCheckpoint, "recordType == LogRecordType.EndCheckpoint"); this.lastCompletedBeginCheckpointRecordOffset = InvalidPhysicalRecordOffset; this.lastCompletedBeginCheckpointRecord = BeginCheckpointLogRecord.InvalidBeginCheckpointLogRecord; }
protected PhysicalLogRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { this.linkedPhysicalRecordOffset = InvalidPhysicalRecordOffset; this.linkedPhysicalRecord = InvalidPhysicalLogRecord; this.nextPhysicalRecord = new WeakReference <PhysicalLogRecord>(InvalidPhysicalLogRecord); }
/** * @ 写入日志 * */ private static void Write(string text, LogType type, Exception ex, LogRecordType recordType) { string dir = string.Format(@"{0}\{1}\{2}\{3}", System.Environment.CurrentDirectory, LogPath, DateTime.Now.ToString("yyyyMMdd"), type.ToString().ToLower()); if (Directory.Exists(dir) == false) { Directory.CreateDirectory(dir); } string df = dateFormarts[recordType.ToInt()]; string path = string.Format("{0}\\{1}.txt", dir, DateTime.Now.ToString(df)); try { lock (LocalLockObj) { using (FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write)) { StreamWriter sw = new StreamWriter(fs); sw.WriteLine(DateTime.Now.ToString() + " " + text); if (ex != null) { sw.WriteLine(ex.Message + " " + ex.StackTrace); if (ex.InnerException != null) { sw.WriteLine(ex.InnerException.StackTrace); } } sw.Flush(); fs.Flush(); } } } catch { } }
internal BackupLogRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { Utility.Assert( recordType == LogRecordType.Backup, "recordType ({0}) == LogRecordType.Backup", recordType); }
internal UpdateEpochLogRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { Utility.Assert(recordType == LogRecordType.UpdateEpoch, "recordType == LogRecordType.UpdateEpoch"); this.epoch = LogicalSequenceNumber.InvalidEpoch; this.primaryReplicaId = ProgressVectorEntry.InvalidReplicaId; this.timestamp = DateTime.MinValue; }
internal CompleteCheckpointLogRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { Utility.Assert( recordType == LogRecordType.CompleteCheckpoint, "Record type is expected to be end rename but the record type is : {0}", recordType); }
internal TruncateHeadLogRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { Utility.Assert(recordType == LogRecordType.TruncateHead, "recordType == LogRecordType.TruncateHead"); this.truncationState = TruncationState.Invalid; this.isStable = false; this.periodicTruncationTimeTicks = 0; }
internal BarrierLogRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { Utility.Assert( recordType == LogRecordType.Barrier, "Expected record type is barrier record, but the actual record type is : {0}", recordType); }
protected string GetLogRecord(string message, LogRecordType logRecordType) { return(string.Format( _logRecordFormat, DateTime.UtcNow, logRecordType, message)); }
public LogRecord(ILogManager logManager, IBufferManager bufferManager, LogRecordType type) { _logManager = logManager; _bufferManager = bufferManager; _type = type; }
public static LogV3EpochLogRecord ReadEpoch(LogRecordType type, byte version, BinaryReader reader) { // temporary: we happen to know the length of an epoch, its always the same. // later we will pass the size in since we will need it for dynamically sized records. var length = Raw.RecordHeader.Size + Raw.EpochHeader.Size; var bytes = ReadBytes(type, version, reader, length); return(new LogV3EpochLogRecord(bytes)); }
internal LogHeadRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { this.logHeadEpoch = LogicalSequenceNumber.InvalidEpoch; this.logHeadLsn = LogicalSequenceNumber.InvalidLsn; this.logHeadPsn = PhysicalSequenceNumber.InvalidPsn; this.logHeadRecordOffset = InvalidPhysicalRecordOffset; this.logHeadRecord = IndexingLogRecord.InvalidIndexingLogRecord; }
/// <summary> /// Gets the app exception DAL. /// </summary> /// <param name="type">The type.</param> /// <returns>IMAppException.</returns> public static IMAppException GetAppExceptionDAL(LogRecordType type) { if (type == LogRecordType.DBLog) { return new DMAppException(); } return new TMAppException(); }
internal OperationLogRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { Utility.Assert(recordType == LogRecordType.Operation, "recordType == LogRecordType.Operation"); this.metaData = null; this.redo = null; this.undo = null; this.operationContext = null; this.isRedoOnly = false; }
internal TransactionLogRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { this.transaction = TransactionBase.InvalidTransaction; this.parentTransactionRecordOffset = InvalidLogicalRecordOffset; this.parentTransactionRecord = InvalidTransactionLogRecord; this.childTransactionRecord = new WeakReference <TransactionLogRecord>(InvalidTransactionLogRecord); this.isEnlistedTransaction = false; }
internal static void Assert(bool condition, string format, bool param1, LogRecordType param2) { if (condition == false) { var failFastMessage = string.Format(System.Globalization.CultureInfo.InvariantCulture, format, param1, param2); FailFast(failFastMessage); // AMW - Force break into debugger for ease of debugging Debugger.Break(); } }
internal EndTransactionLogRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { Utility.Assert( recordType == LogRecordType.EndTransaction, "LogRecordType {0} != EndTransaction", recordType); this.ChildTransactionRecord = null; this.isCommitted = false; this.isThisReplicaTransaction = false; }
public static byte[] ReadBytes(LogRecordType type, byte version, BinaryReader reader, int recordLength) { // todo: if we could get some confidence that we would return to the pool // (e.g. with reference counting) then we could use arraypool here. or just maybe a ring buffer // var bytes = ArrayPool<byte>.Shared.Rent(length); var bytes = new byte[recordLength]; bytes[0] = (byte)type; bytes[1] = version; reader.Read(bytes.AsSpan(2..recordLength)); return(bytes); }
internal BeginTransactionOperationLogRecord(LogRecordType recordType, ulong recordPosition, long lsn) : base(recordType, recordPosition, lsn) { this.isSingleOperationTransaction = false; this.ParentTransactionRecord = null; Utility.Assert(recordType == LogRecordType.BeginTransaction, "recordType == LogRecordType.BeginTransaction"); this.recordEpoch = LogicalSequenceNumber.InvalidEpoch; this.metaData = null; this.redo = null; this.undo = null; this.operationContext = null; }
public static LogRecordStats GetStatsForRecordType(LogRecordType recordType) { switch (recordType) { case LogRecordType.BeginTransaction: return(new OperationLogRecordStats(recordType)); case LogRecordType.Operation: return(new OperationLogRecordStats(recordType)); } return(new LogRecordStats(recordType)); }
private void FlushBuffer(bool recordCompleted, bool force, bool flushToDisk) { switch (currentRecordType) { case LogRecordType.FullType: currentRecordType = recordCompleted ? LogRecordType.FullType : LogRecordType.StartType; break; case LogRecordType.StartType: currentRecordType = recordCompleted ? LogRecordType.EndType : LogRecordType.MiddleType; break; case LogRecordType.MiddleType: currentRecordType = recordCompleted ? LogRecordType.EndType : LogRecordType.MiddleType; break; default: throw new ArgumentOutOfRangeException("Cannot flush when the currentRecordType is: " + currentRecordType); } EmitPhysicalRecord(currentRecordType, _buffer, HeaderSize, _bufferPos - HeaderSize, force, flushToDisk); if (recordCompleted) { currentRecordType = LogRecordType.FullType; _bufferPos = HeaderSize; } }
protected LogRecord(LogRecordType recordType, byte version) { RecordType = recordType; Version = version; }
public void RecordCompleted(bool flushToDisk) { FlushBuffer(recordCompleted: true, force: true, flushToDisk: flushToDisk); _lastCompletedRecordStreamLength = _binaryWriter.BaseStream.Length; currentRecordType = LogRecordType.ZeroType; }
public void RecordStarted() { currentRecordType = LogRecordType.FullType; }
private void EmitPhysicalRecord(LogRecordType type, byte[] buffer, int offset, int count, bool force, bool flushToDisk) { // calc crc & write header var crc = Crc.Extend(RecordTypeCrcs[type], buffer, offset, count); _binaryWriter.Write(Crc.Mask(crc)); _binaryWriter.Write((ushort)count); _binaryWriter.Write((byte)type); _binaryWriter.Write(buffer, offset, count); if (force) _fileSystem.Flush(_binaryWriter.BaseStream, flushToDisk); _bufferPos += HeaderSize; }