/// <summary> /// Initializes a new <see cref="CKExceptionData"/> with all its fields. /// Use the factory method <see cref="CreateFrom"/> to create a data from any exception. /// </summary> /// <param name="message">Message of the exception. Must not be null.</param> /// <param name="exceptionTypeName">Type name of the exception (no namespace nor assembly). Must not be null nor empty..</param> /// <param name="exceptionTypeAssemblyQualifiedName">Full type name of the exception. Must not be null nor empty.</param> /// <param name="stackTrace">Stack trace. Can be null.</param> /// <param name="innerException">Inner exception. If <paramref name="aggregatedExceptions"/> is not null, it must be the same as the first aggregated exceptions.</param> /// <param name="fileName">File name related to the exception (if it makes sense). Can be null.</param> /// <param name="detailedInfo">More detailed information if any.</param> /// <param name="loaderExceptions">Loader exceptions. <see cref="LoaderExceptions"/>.</param> /// <param name="aggregatedExceptions">Aggregated exceptions can be null. Otherwise, it must contain at least one exception.</param> public CKExceptionData( string message, string exceptionTypeName, string exceptionTypeAssemblyQualifiedName, string stackTrace, CKExceptionData innerException, string fileName, string detailedInfo, CKExceptionData[] loaderExceptions, CKExceptionData[] aggregatedExceptions ) { if( message == null ) throw new ArgumentNullException( nameof( message ) ); if( String.IsNullOrWhiteSpace( exceptionTypeName ) ) throw new ArgumentNullException( nameof( exceptionTypeName ) ); if( String.IsNullOrWhiteSpace( exceptionTypeAssemblyQualifiedName ) ) throw new ArgumentNullException( nameof( exceptionTypeAssemblyQualifiedName ) ); if( aggregatedExceptions != null && aggregatedExceptions.Length == 0 ) throw new ArgumentException( Impl.CoreResources.AggregatedExceptionsMustContainAtLeastOne, nameof( aggregatedExceptions ) ); if( innerException != null && aggregatedExceptions != null && aggregatedExceptions[0] != innerException ) throw new ArgumentException( Impl.CoreResources.InnerExceptionMustBeTheFirstAggregatedException ); // No empty array for loaderExceptions: null or at least one inside. if( loaderExceptions != null && loaderExceptions.Length == 0 ) loaderExceptions = null; _message = message; _exceptionTypeName = exceptionTypeName; _exceptionTypeAQName = exceptionTypeAssemblyQualifiedName; _stackTrace = String.IsNullOrWhiteSpace( stackTrace ) ? null : stackTrace; _innerException = innerException; _fileName = fileName; _detailedInfo = detailedInfo; _loaderExceptions = loaderExceptions; _aggregatedExceptions = aggregatedExceptions; }
/// <summary> /// Creates a <see cref="CKException"/> from a <see cref="CKExceptionData"/>. This method returns null when data is null. /// This is the symmetric of <see cref="CKExceptionData.CreateFrom"/>. /// </summary> /// <param name="data">Data of an exception for which a <see cref="CKException"/> wrapper must be created. Can be null: null is returned.</param> /// <returns>The exception that wraps the data.</returns> static public CKException CreateFrom(CKExceptionData data) { if (data == null) { return(null); } return(new CKException(data)); }
/// <summary> /// If <see cref="ExceptionData"/> is null, this method creates the <see cref="CKExceptionData"/> /// with the details from this exception. /// </summary> /// <returns>The <see cref="CKExceptionData"/> that describes this exception.</returns> public CKExceptionData EnsureExceptionData() { if (_exceptionData == null) { _exceptionData = new CKExceptionData(Message, "CKException", GetType().AssemblyQualifiedName, StackTrace, CKExceptionData.CreateFrom(InnerException), null, null, null, null); } return(_exceptionData); }
public LEMCLog( Guid monitorId, int depth, DateTimeStamp previousLogTime, LogEntryType previousEntryType, string text, DateTimeStamp t, string fileName, int lineNumber, LogLevel l, CKTrait tags, CKExceptionData ex ) : base( text, t, fileName, lineNumber, l, tags, ex ) { _monitorId = monitorId; _depth = depth; _previousEntryType = previousEntryType; _previousLogTime = previousLogTime; }
public LEOpenGroup( LEMCOpenGroup e ) { _text = e.Text; _time = e.LogTime; _fileName = e.FileName; _lineNumber = e.LineNumber; _level = e.LogLevel; _tags = e.Tags; _ex = e.Exception; }
public LEOpenGroup( string text, DateTimeStamp t, string fileName, int lineNumber, LogLevel l, CKTrait tags, CKExceptionData ex ) { _text = text; _time = t; _fileName = fileName; _lineNumber = lineNumber; _level = l; _tags = tags; _ex = ex; }
public void LogEntryReadWrite() { var exInner = new CKExceptionData( "message", "typeof(exception)", "assemblyQualifiedName", "stackTrace", null, "fileName", "fusionLog", null, null ); var ex2 = new CKExceptionData( "message2", "typeof(exception2)", "assemblyQualifiedName2", "stackTrace2", exInner, "fileName2", "fusionLog2", null, null ); var exL = new CKExceptionData( "loader-message", "typeof(loader-exception)", "loader-assemblyQualifiedName", "loader-stackTrace", null, "loader-fileName", "loader-fusionLog", null, null ); var exAgg = new CKExceptionData( "agg-message", "typeof(agg-exception)", "agg-assemblyQualifiedName", "agg-stackTrace", ex2, "fileName", "fusionLog", null, new[]{ ex2, exL } ); var prevLog = DateTimeStamp.UtcNow; ILogEntry e1 = LogEntry.CreateLog( "Text1", new DateTimeStamp( DateTime.UtcNow, 42 ), LogLevel.Info, "c:\\test.cs", 3712, ActivityMonitor.Tags.CreateDependentActivity, exAgg ); ILogEntry e2 = LogEntry.CreateMulticastLog( Guid.Empty, LogEntryType.Line, prevLog, 5, "Text2", DateTimeStamp.UtcNow, LogLevel.Fatal, null, 3712, ActivityMonitor.Tags.CreateDependentActivity, exAgg ); using( var mem = new MemoryStream() ) using( var w = new CKBinaryWriter( mem ) ) { w.Write( LogReader.CurrentStreamVersion ); e1.WriteLogEntry( w ); e2.WriteLogEntry( w ); w.Write( (byte)0 ); w.Flush(); byte[] versionBytes = new byte[4]; mem.Position = 0; mem.Read( versionBytes, 0, 4 ); Assert.That( BitConverter.ToInt32( versionBytes, 0 ), Is.EqualTo( LogReader.CurrentStreamVersion ) ); using( var reader = new LogReader( mem, LogReader.CurrentStreamVersion, 4 ) ) { Assert.That( reader.MoveNext() ); Assert.That( reader.Current.Text, Is.EqualTo( e1.Text ) ); Assert.That( reader.Current.LogLevel, Is.EqualTo( e1.LogLevel ) ); Assert.That( reader.Current.LogTime, Is.EqualTo( e1.LogTime ) ); Assert.That( reader.Current.FileName, Is.EqualTo( e1.FileName ) ); Assert.That( reader.Current.LineNumber, Is.EqualTo( e1.LineNumber ) ); Assert.That( reader.Current.Exception.ExceptionTypeAssemblyQualifiedName, Is.EqualTo( e1.Exception.ExceptionTypeAssemblyQualifiedName ) ); Assert.That( reader.Current.Exception.ToString(), Is.EqualTo( e1.Exception.ToString() ) ); Assert.That( reader.MoveNext() ); Assert.That( reader.CurrentMulticast.PreviousEntryType, Is.EqualTo( LogEntryType.Line ) ); Assert.That( reader.CurrentMulticast.PreviousLogTime, Is.EqualTo( prevLog ) ); Assert.That( reader.Current.Text, Is.EqualTo( e2.Text ) ); Assert.That( reader.Current.LogTime, Is.EqualTo( e2.LogTime ) ); Assert.That( reader.Current.FileName, Is.Null ); Assert.That( reader.Current.LineNumber, Is.EqualTo( 0 ), "Since no file name is set, line number is 0." ); Assert.That( reader.Current.Exception.ExceptionTypeAssemblyQualifiedName, Is.EqualTo( e2.Exception.ExceptionTypeAssemblyQualifiedName ) ); Assert.That( reader.Current.Exception.ToString(), Is.EqualTo( e2.Exception.ToString() ) ); Assert.That( reader.MoveNext(), Is.False ); Assert.That( reader.BadEndOfFileMarker, Is.False ); } } }
/// <summary> /// Initializes a new <see cref="CKExceptionData"/> with all its fields. /// Use the factory method <see cref="CreateFrom"/> to create a data from any exception. /// </summary> /// <param name="message">Message of the exception. Must not be null.</param> /// <param name="exceptionTypeName">Type name of the exception (no namespace nor assembly). Must not be null nor empty..</param> /// <param name="exceptionTypeAssemblyQualifiedName">Full type name of the exception. Must not be null nor empty.</param> /// <param name="stackTrace">Stack trace. Can be null.</param> /// <param name="innerException">Inner exception. If <paramref name="aggregatedExceptions"/> is not null, it must be the same as the first aggregated exceptions.</param> /// <param name="fileName">File name related to the exception (if it makes sense). Can be null.</param> /// <param name="detailedInfo">More detailed information if any.</param> /// <param name="loaderExceptions">Loader exceptions. <see cref="LoaderExceptions"/>.</param> /// <param name="aggregatedExceptions">Aggregated exceptions can be null. Otherwise, it must contain at least one exception.</param> public CKExceptionData( string message, string exceptionTypeName, string exceptionTypeAssemblyQualifiedName, string stackTrace, CKExceptionData innerException, string fileName, string detailedInfo, CKExceptionData[] loaderExceptions, CKExceptionData[] aggregatedExceptions) { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (String.IsNullOrWhiteSpace(exceptionTypeName)) { throw new ArgumentNullException(nameof(exceptionTypeName)); } if (String.IsNullOrWhiteSpace(exceptionTypeAssemblyQualifiedName)) { throw new ArgumentNullException(nameof(exceptionTypeAssemblyQualifiedName)); } if (aggregatedExceptions != null && aggregatedExceptions.Length == 0) { throw new ArgumentException(Impl.CoreResources.AggregatedExceptionsMustContainAtLeastOne, nameof(aggregatedExceptions)); } if (innerException != null && aggregatedExceptions != null && aggregatedExceptions[0] != innerException) { throw new ArgumentException(Impl.CoreResources.InnerExceptionMustBeTheFirstAggregatedException); } // No empty array for loaderExceptions: null or at least one inside. if (loaderExceptions != null && loaderExceptions.Length == 0) { loaderExceptions = null; } _message = message; _exceptionTypeName = exceptionTypeName; _exceptionTypeAQName = exceptionTypeAssemblyQualifiedName; _stackTrace = String.IsNullOrWhiteSpace(stackTrace) ? null : stackTrace; _innerException = innerException; _fileName = fileName; _detailedInfo = detailedInfo; _loaderExceptions = loaderExceptions; _aggregatedExceptions = aggregatedExceptions; }
/// <summary> /// Initializes a new <see cref="CKExceptionData"/> from a <see cref="CKBinaryReader"/> /// with a known version. /// See <see cref="Write(CKBinaryWriter,bool)"/>. /// </summary> /// <param name="r">The reader to read from.</param> /// <param name="streamIsCRLF">Whether the strings have CRLF or LF for end-of-lines.</param> /// <param name="version">Known version.</param> public CKExceptionData(CKBinaryReader r, bool streamIsCRLF, int version) { if (r == null) { throw new ArgumentNullException("r"); } _message = r.ReadString(streamIsCRLF); _exceptionTypeName = r.ReadString(); _exceptionTypeAQName = r.ReadString(); _stackTrace = r.ReadNullableString(streamIsCRLF); _fileName = r.ReadNullableString(); _detailedInfo = r.ReadNullableString(streamIsCRLF); int nbAgg = version == 0 ? r.ReadInt32() : r.ReadSmallInt32(); if (nbAgg > 0) { _aggregatedExceptions = new CKExceptionData[nbAgg]; for (int i = 0; i < nbAgg; ++i) { _aggregatedExceptions[i] = new CKExceptionData(r, streamIsCRLF, version == 0 ? r.ReadInt32() : version); } _innerException = _aggregatedExceptions[0]; } else { if (nbAgg == 0) { _innerException = new CKExceptionData(r, streamIsCRLF, version == 0 ? r.ReadInt32() : version); } } int nbLd = version == 0 ? r.ReadInt32() : r.ReadNonNegativeSmallInt32(); if (nbLd != 0) { _loaderExceptions = new CKExceptionData[nbLd]; for (int i = 0; i < nbLd; ++i) { _loaderExceptions[i] = new CKExceptionData(r, streamIsCRLF, version == 0 ? r.ReadInt32() : version); } } }
/// <summary> /// Gets or creates the <see cref="CKExceptionData"/> that captures exception information. /// If <see cref="P:Exception"/> is null, this returns null. /// </summary> /// <returns>A data representation of the exception or null.</returns> public CKExceptionData EnsureExceptionData() { return _exceptionData ?? (_exceptionData = CKExceptionData.CreateFrom( _exception )); }
/// <summary> /// Gets or creates the <see cref="CKExceptionData"/> that captures exception information. /// If <see cref="P:Exception"/> is null, this returns null. /// </summary> /// <returns>A data representation of the exception or null.</returns> public CKExceptionData EnsureExceptionData() { return(_exceptionData ?? (_exceptionData = CKExceptionData.CreateFrom(_exception))); }
/// <summary> /// Reads a <see cref="ILogEntry"/> from the binary reader that can be a <see cref="IMulticastLogEntry"/>. /// If the first read byte is 0, read stops and null is returned. /// The 0 byte is the "end marker" that <see cref="CKMonWriterClient.Close()"/> write, but this /// method can read non zero-terminated streams (it catches an EndOfStreamException when reading the first byte and handles it silently). /// This method can throw any type of exception (<see cref="System.IO.EndOfStreamException"/> or <see cref="InvalidDataException"/> for instance) that /// must be handled by the caller. /// </summary> /// <param name="r">The binary reader.</param> /// <param name="streamVersion">The version of the stream.</param> /// <param name="badEndOfFile">True whenever the end of file is the result of an <see cref="EndOfStreamException"/>.</param> /// <returns>The log entry or null if a zero byte (end marker) has been found.</returns> static public ILogEntry Read( CKBinaryReader r, int streamVersion, out bool badEndOfFile ) { if( r == null ) throw new ArgumentNullException( "r" ); badEndOfFile = false; StreamLogType t = StreamLogType.EndOfStream; LogLevel logLevel = LogLevel.None; try { ReadLogTypeAndLevel( r, out t, out logLevel ); } catch( EndOfStreamException ) { badEndOfFile = true; // Silently ignores here reading beyond the stream: this // kindly handles the lack of terminating 0 byte. } if( t == StreamLogType.EndOfStream ) return null; if( (t & StreamLogType.TypeMask) == StreamLogType.TypeGroupClosed ) { return ReadGroupClosed( streamVersion, r, t, logLevel ); } DateTimeStamp time = new DateTimeStamp( DateTime.FromBinary( r.ReadInt64() ), (t & StreamLogType.HasUniquifier) != 0 ? r.ReadByte() : (Byte)0 ); if( time.TimeUtc.Year < 2014 || time.TimeUtc.Year > 3000 ) throw new InvalidDataException( "Date year before 2014 or after 3000 are considered invalid." ); CKTrait tags = ActivityMonitor.Tags.Empty; string fileName = null; int lineNumber = 0; CKExceptionData ex = null; string text = null; if( (t & StreamLogType.HasTags) != 0 ) tags = ActivityMonitor.Tags.Register( r.ReadString() ); if( (t & StreamLogType.HasFileName) != 0 ) { fileName = r.ReadString(); lineNumber = streamVersion < 6 ? r.ReadInt32() : r.ReadNonNegativeSmallInt32(); if( lineNumber > 100*1000 ) throw new InvalidDataException( "LineNumber greater than 100K is considered invalid." ); } if( (t & StreamLogType.HasException) != 0 ) { ex = new CKExceptionData( r, (t & StreamLogType.IsLFOnly) == 0 ); if( (t & StreamLogType.IsTextTheExceptionMessage) != 0 ) text = ex.Message; } if( text == null ) text = r.ReadString( (t & StreamLogType.IsLFOnly) == 0 ); Guid mId; int depth; LogEntryType prevType; DateTimeStamp prevTime; if( (t & StreamLogType.TypeMask) == StreamLogType.TypeLine ) { if( (t & StreamLogType.IsMultiCast) == 0 ) { return new LELog( text, time, fileName, lineNumber, logLevel, tags, ex ); } ReadMulticastFooter( streamVersion, r, t, out mId, out depth, out prevType, out prevTime ); return new LEMCLog( mId, depth, prevTime, prevType, text, time, fileName, lineNumber, logLevel, tags, ex ); } if( (t & StreamLogType.TypeMask) != StreamLogType.TypeOpenGroup ) throw new InvalidDataException(); if( (t & StreamLogType.IsMultiCast) == 0 ) { return new LEOpenGroup( text, time, fileName, lineNumber, logLevel, tags, ex ); } ReadMulticastFooter( streamVersion, r, t, out mId, out depth, out prevType, out prevTime ); return new LEMCOpenGroup( mId, depth, prevTime, prevType, text, time, fileName, lineNumber, logLevel, tags, ex ); }
static void DoWriteLog( CKBinaryWriter w, StreamLogType t, LogLevel level, DateTimeStamp logTime, string text, CKTrait tags, CKExceptionData ex, string fileName, int lineNumber ) { if( tags != null && !tags.IsEmpty ) t |= StreamLogType.HasTags; if( ex != null ) { t |= StreamLogType.HasException; if( text == ex.Message ) t |= StreamLogType.IsTextTheExceptionMessage; } if( fileName != null ) t |= StreamLogType.HasFileName; if( logTime.Uniquifier != 0 ) t |= StreamLogType.HasUniquifier; WriteLogTypeAndLevel( w, t, level ); w.Write( logTime.TimeUtc.ToBinary() ); if( logTime.Uniquifier != 0 ) w.Write( logTime.Uniquifier ); if( (t & StreamLogType.HasTags) != 0 ) w.Write( tags.ToString() ); if( (t & StreamLogType.HasFileName) != 0 ) { w.Write( fileName ); w.WriteNonNegativeSmallInt32( lineNumber ); } if( (t & StreamLogType.HasException) != 0 ) ex.Write( w ); if( (t & StreamLogType.IsTextTheExceptionMessage) == 0 ) w.Write( text ); }
/// <summary> /// Initializes a new <see cref="CKException"/> with an <see cref="ExceptionData"/>. /// The message of this exception is the <see cref="CKExceptionData.Message"/>. /// Use the static <see cref="CreateFrom"/> to handle null data (a null CKException will be returned). /// </summary> /// <param name="data">The exception data. Must not be null.</param> public CKException(CKExceptionData data) : this(data.Message) { _exceptionData = data; }
/// <summary> /// If <see cref="ExceptionData"/> is null, this method creates the <see cref="CKExceptionData"/> with the details /// from this exception. /// </summary> /// <returns>The <see cref="CKExceptionData"/> that describes this exception.</returns> public CKExceptionData EnsureExceptionData() { if( _exceptionData == null ) { _exceptionData = new CKExceptionData( Message, "CKException", GetType().AssemblyQualifiedName, StackTrace, CKExceptionData.CreateFrom( InnerException ), null, null, null, null ); } return _exceptionData; }
static string DumpErrorText(DateTimeStamp logTime, string text, LogLevel level, CKTrait tags, CKExceptionData exData) { StringBuilder buffer = CreateHeader(logTime, text, level, tags); if (exData != null) { exData.ToStringBuilder(buffer, String.Empty); } WriteFooter(level, buffer); return(buffer.ToString()); }
/// <summary> /// Initializes a new <see cref="CKException"/> with an <see cref="ExceptionData"/>. /// The message of this exception is the <see cref="CKExceptionData.Message"/>. /// Use the static <see cref="CreateFrom"/> to handle null data (a null CKException will be returned). /// </summary> /// <param name="data">The exception data. Must not be null.</param> public CKException( CKExceptionData data ) : this( data.Message ) { _exceptionData = data; }
/// <summary> /// Binary writes a log entry. /// </summary> /// <param name="w">Binary writer to use.</param> /// <param name="isOpenGroup">True if this the opening of a group. False for a line.</param> /// <param name="level">Log level of the log entry.</param> /// <param name="text">Text of the log entry.</param> /// <param name="logTime">Time stamp of the log entry.</param> /// <param name="tags">Tags of the log entry</param> /// <param name="ex">Exception of the log entry.</param> /// <param name="fileName">Source file name of the log entry</param> /// <param name="lineNumber">Source line number of the log entry</param> static public void WriteLog( CKBinaryWriter w, bool isOpenGroup, LogLevel level, DateTimeStamp logTime, string text, CKTrait tags, CKExceptionData ex, string fileName, int lineNumber ) { if( w == null ) throw new ArgumentNullException( "w" ); DoWriteLog( w, isOpenGroup ? StreamLogType.TypeOpenGroup : StreamLogType.TypeLine, level, logTime, text, tags, ex, fileName, lineNumber ); }
/// <summary> /// Initializes a new <see cref="CKExceptionData"/> from a <see cref="CKBinaryReader"/> /// with a known version. /// See <see cref="Write(CKBinaryWriter,bool)"/>. /// </summary> /// <param name="r">The reader to read from.</param> /// <param name="streamIsCRLF">Whether the strings have CRLF or LF for end-of-lines.</param> /// <param name="version">Known version.</param> public CKExceptionData( CKBinaryReader r, bool streamIsCRLF, int version ) { if( r == null ) throw new ArgumentNullException( "r" ); _message = r.ReadString( streamIsCRLF ); _exceptionTypeName = r.ReadString(); _exceptionTypeAQName = r.ReadString(); _stackTrace = r.ReadNullableString( streamIsCRLF ); _fileName = r.ReadNullableString(); _detailedInfo = r.ReadNullableString( streamIsCRLF ); int nbAgg = version == 0 ? r.ReadInt32() : r.ReadSmallInt32(); if( nbAgg > 0 ) { _aggregatedExceptions = new CKExceptionData[nbAgg]; for( int i = 0; i < nbAgg; ++i ) _aggregatedExceptions[i] = new CKExceptionData( r, streamIsCRLF, version == 0 ? r.ReadInt32() : version ); _innerException = _aggregatedExceptions[0]; } else { if( nbAgg == 0 ) _innerException = new CKExceptionData( r, streamIsCRLF, version == 0 ? r.ReadInt32() : version ); } int nbLd = version == 0 ? r.ReadInt32() : r.ReadNonNegativeSmallInt32(); if( nbLd != 0 ) { _loaderExceptions = new CKExceptionData[nbLd]; for( int i = 0; i < nbLd; ++i ) _loaderExceptions[i] = new CKExceptionData( r, streamIsCRLF, version == 0 ? r.ReadInt32() : version ); } }
/// <summary> /// Creates a <see cref="CKExceptionData"/> from any <see cref="Exception"/>. /// </summary> /// <param name="ex">Exception for which data must be created. Can be null: null is returned.</param> /// <returns>The data that describes the exception.</returns> static public CKExceptionData CreateFrom( Exception ex ) { if( ex == null ) return null; CKException ckEx = ex as CKException; if( ckEx != null ) return ckEx.EnsureExceptionData(); Type t = ex.GetType(); string exceptionTypeName = t.Name; string exceptionTypeAssemblyQualifiedName = t.AssemblyQualifiedName; CKExceptionData innerException; CKExceptionData[] aggregatedExceptions = null; var aggEx = ex as AggregateException; if( aggEx != null ) { CKExceptionData[] a = new CKExceptionData[aggEx.InnerExceptions.Count]; for( int i = 0; i < a.Length; ++i ) a[i] = CreateFrom( aggEx.InnerExceptions[i] ); innerException = a[0]; aggregatedExceptions = a; } else innerException = CreateFrom( ex.InnerException ); string fileName = null; string detailedInfo = null; CKExceptionData[] loaderExceptions = null; var typeLoadEx = ex as ReflectionTypeLoadException; if( typeLoadEx != null ) { CKExceptionData[] a = new CKExceptionData[typeLoadEx.LoaderExceptions.Length]; for( int i = 0; i < a.Length; ++i ) a[i] = CreateFrom( typeLoadEx.LoaderExceptions[i] ); loaderExceptions = a; } else { var fileNFEx = ex as System.IO.FileNotFoundException; if( fileNFEx != null ) { fileName = fileNFEx.FileName; #if NET451 || NET46 detailedInfo = fileNFEx.FusionLog.NormalizeEOL(); #endif } else { var loadFileEx = ex as System.IO.FileLoadException; if( loadFileEx != null ) { fileName = loadFileEx.FileName; #if NET451 || NET46 detailedInfo = loadFileEx.FusionLog.NormalizeEOL(); #endif } else { #if NET451 || NET46 var configEx = ex as System.Configuration.ConfigurationException; if( configEx != null ) { fileName = configEx.Filename; } #endif } } } return new CKExceptionData( ex.Message, exceptionTypeName, exceptionTypeAssemblyQualifiedName, ex.StackTrace, innerException, fileName, detailedInfo, loaderExceptions, aggregatedExceptions ); }
/// <summary> /// Creates a <see cref="ILogEntry"/> for an opened group. /// </summary> /// <param name="text">Text of the log entry.</param> /// <param name="t">Time stamp of the log entry.</param> /// <param name="level">Log level of the log entry.</param> /// <param name="fileName">Source file name of the log entry</param> /// <param name="lineNumber">Source line number of the log entry</param> /// <param name="tags">Tags of the log entry</param> /// <param name="ex">Exception of the log entry.</param> /// <returns>A log entry object.</returns> public static ILogEntry CreateOpenGroup( string text, DateTimeStamp t, LogLevel level, string fileName, int lineNumber, CKTrait tags, CKExceptionData ex ) { return new LEOpenGroup( text, t, fileName, lineNumber, level, tags, ex ); }
/// <summary> /// Creates a <see cref="ILogEntry"/> for a line. /// </summary> /// <param name="monitorId">Identifier of the monitor.</param> /// <param name="previousEntryType">Log type of the previous entry in the monitor..</param> /// <param name="previousLogTime">Time stamp of the previous entry in the monitor.</param> /// <param name="depth">Depth of the line (number of opened groups above).</param> /// <param name="text">Text of the log entry.</param> /// <param name="t">Time stamp of the log entry.</param> /// <param name="level">Log level of the log entry.</param> /// <param name="fileName">Source file name of the log entry</param> /// <param name="lineNumber">Source line number of the log entry</param> /// <param name="tags">Tags of the log entry</param> /// <param name="ex">Exception of the log entry.</param> /// <returns>A log entry object.</returns> public static IMulticastLogEntry CreateMulticastLog( Guid monitorId, LogEntryType previousEntryType, DateTimeStamp previousLogTime, int depth, string text, DateTimeStamp t, LogLevel level, string fileName, int lineNumber, CKTrait tags, CKExceptionData ex ) { return new LEMCLog( monitorId, depth, previousLogTime, previousEntryType, text, t, fileName, lineNumber, level, tags, ex ); }
/// <summary> /// Creates a <see cref="CKExceptionData"/> from any <see cref="Exception"/>. /// </summary> /// <param name="ex">Exception for which data must be created. Can be null: null is returned.</param> /// <returns>The data that describes the exception.</returns> static public CKExceptionData CreateFrom(Exception ex) { if (ex == null) { return(null); } Type t = ex.GetType(); string exceptionTypeName = t.Name; string exceptionTypeAssemblyQualifiedName = t.AssemblyQualifiedName; CKExceptionData innerException; CKExceptionData[] aggregatedExceptions = null; var aggEx = ex as AggregateException; if (aggEx != null) { CKExceptionData[] a = new CKExceptionData[aggEx.InnerExceptions.Count]; for (int i = 0; i < a.Length; ++i) { a[i] = CreateFrom(aggEx.InnerExceptions[i]); } innerException = a[0]; aggregatedExceptions = a; } else { innerException = CreateFrom(ex.InnerException); } string fileName = null; string detailedInfo = null; CKExceptionData[] loaderExceptions = null; var typeLoadEx = ex as ReflectionTypeLoadException; if (typeLoadEx != null) { CKExceptionData[] a = new CKExceptionData[typeLoadEx.LoaderExceptions.Length]; for (int i = 0; i < a.Length; ++i) { a[i] = CreateFrom(typeLoadEx.LoaderExceptions[i]); } loaderExceptions = a; } else { var fileNFEx = ex as System.IO.FileNotFoundException; if (fileNFEx != null) { fileName = fileNFEx.FileName; detailedInfo = fileNFEx.FusionLog.NormalizeEOL(); } else { var loadFileEx = ex as System.IO.FileLoadException; if (loadFileEx != null) { fileName = loadFileEx.FileName; detailedInfo = loadFileEx.FusionLog.NormalizeEOL(); } } } return(new CKExceptionData(ex.Message, exceptionTypeName, exceptionTypeAssemblyQualifiedName, ex.StackTrace, innerException, fileName, detailedInfo, loaderExceptions, aggregatedExceptions)); }
/// <summary> /// Creates a <see cref="CKException"/> from a <see cref="CKExceptionData"/>. This method returns null when data is null. /// This is the symmetric of <see cref="CKExceptionData.CreateFrom"/>. /// </summary> /// <param name="data">Data of an exception for which a <see cref="CKException"/> wrapper must be created. Can be null: null is returned.</param> /// <returns>The exception that wraps the data.</returns> static public CKException CreateFrom( CKExceptionData data ) { if( data == null ) return null; return new CKException( data ); }
/// <summary> /// Binary writes a multicast log entry. /// </summary> /// <param name="w">Binary writer to use.</param> /// <param name="monitorId">Identifier of the monitor.</param> /// <param name="previousEntryType">Log type of the previous entry in the monitor..</param> /// <param name="previousLogTime">Time stamp of the previous entry in the monitor.</param> /// <param name="depth">Depth of the line (number of opened groups above).</param> /// <param name="isOpenGroup">True if this the opening of a group. False for a line.</param> /// <param name="text">Text of the log entry.</param> /// <param name="level">Log level of the log entry.</param> /// <param name="logTime">Time stamp of the log entry.</param> /// <param name="tags">Tags of the log entry</param> /// <param name="ex">Exception of the log entry.</param> /// <param name="fileName">Source file name of the log entry</param> /// <param name="lineNumber">Source line number of the log entry</param> static public void WriteLog( CKBinaryWriter w, Guid monitorId, LogEntryType previousEntryType, DateTimeStamp previousLogTime, int depth, bool isOpenGroup, LogLevel level, DateTimeStamp logTime, string text, CKTrait tags, CKExceptionData ex, string fileName, int lineNumber ) { if( w == null ) throw new ArgumentNullException( "w" ); StreamLogType type = StreamLogType.IsMultiCast | (isOpenGroup ? StreamLogType.TypeOpenGroup : StreamLogType.TypeLine); type = UpdateTypeWithPrevious( type, previousEntryType, ref previousLogTime ); DoWriteLog( w, type, level, logTime, text, tags, ex, fileName, lineNumber ); WriteMulticastFooter( w, monitorId, previousEntryType, previousLogTime, depth ); }
static string DumpErrorText( DateTimeStamp logTime, string text, LogLevel level, CKTrait tags, CKExceptionData exData ) { StringBuilder buffer = CreateHeader( logTime, text, level, tags ); if( exData != null ) exData.ToStringBuilder( buffer, String.Empty ); WriteFooter( level, buffer ); return buffer.ToString(); }