예제 #1
0
        public void Append(LogGroup group)
        {
            List <LogGroup> list = new List <LogGroup>();

            list.Add(group);
            SubGroups = list.ToArray();
        }
        public CorruptLogException(LogGroup group)
            : base("The log has been corrupted while in memory.\n"
		                                                  + "Group ID: " + group.ID.ToString() + "\n"
		                                                  + "Parent ID: " + group.ParentID.ToString() + "\n"
		                                                  + "Summary: " + group.Summary + "\n"
		                                                  + "Current group ID: " + DiagnosticState.CurrentGroupID.ToString() + "\n")
        {
        }
 public CorruptLogException(LogGroup group) : base("The log has been corrupted while in memory.\n"
                                                   + "Group ID: " + group.ID.ToString() + "\n"
                                                   + "Parent ID: " + group.ParentID.ToString() + "\n"
                                                   + "Summary: " + group.Summary + "\n"
                                                   + "Current group ID: " + DiagnosticState.CurrentGroupID.ToString() + "\n"
                                                   )
 {
 }
예제 #4
0
        /// <summary>
        /// Adds the provided log group to the stack.
        /// </summary>
        /// <param name="group">The group to add to the stack.</param>
        public static void PushGroup(LogGroup group)
        {
            if (group == null)
                throw new ArgumentNullException("group");

            group.Parent = DiagnosticState.CurrentGroup;

            CurrentGroup = group;
        }
예제 #5
0
        /// <summary>
        /// Checks whether the provided group can be popped from the list.
        /// </summary>
        /// <param name="endingGroup"></param>
        /// <param name="currentGroup"></param>
        /// <returns></returns>
        public bool CanPop(LogGroup endingGroup, LogGroup currentGroup)
        {
            if (endingGroup == null)
                throw new ArgumentNullException("endingGroup");

            return currentGroup != null
                && currentGroup.ID != Guid.Empty
                && endingGroup.ParentID != currentGroup.ID
                && HasParent(currentGroup, endingGroup.ID); // If the ending group is a parent of the current group then it matches
        }
예제 #6
0
        /// <summary>
        /// Adds the provided log group to the stack.
        /// </summary>
        /// <param name="group">The group to add to the stack.</param>
        static public void PushGroup(LogGroup group)
        {
            if (group == null)
            {
                throw new ArgumentNullException("group");
            }

            group.Parent = DiagnosticState.CurrentGroup;

            CurrentGroup = group;
        }
예제 #7
0
        /// <summary>
        /// Checks whether the provided group can be popped from the list.
        /// </summary>
        /// <param name="endingGroup"></param>
        /// <param name="currentGroup"></param>
        /// <returns></returns>
        public bool CanPop(LogGroup endingGroup, LogGroup currentGroup)
        {
            if (endingGroup == null)
            {
                throw new ArgumentNullException("endingGroup");
            }

            return(currentGroup != null &&
                   currentGroup.ID != Guid.Empty &&
                   endingGroup.ParentID != currentGroup.ID &&
                   HasParent(currentGroup, endingGroup.ID));                // If the ending group is a parent of the current group then it matches
        }
예제 #8
0
        static public Type GetPropertyType(object obj, string propertyName)
        {
            PropertyInfo property   = null;
            object       value      = obj;
            Type         returnType = null;

            if (obj == null)
            {
                throw new ArgumentException("obj cannot be null");
            }

            using (LogGroup logGroup = LogGroup.Start("Retrieving property '" + propertyName + "' from type '" + obj.GetType(), LogLevel.Debug))
            {
                string[] parts = propertyName.Split('.');

                foreach (string part in parts)
                {
                    LogWriter.Debug("Stepping to property '" + part + "' of type '" + value.GetType().ToString() + "'.");

                    property = value.GetType().GetProperty(part);

                    if (property == null)
                    {
                        throw new ArgumentException("The property '" + part + "' wasn't found on the type '" + value.GetType().ToString() + "'.");
                    }

                    LogWriter.Debug("Property type: " + property.PropertyType.FullName);

                    value = property.GetValue(value, null);

                    returnType = property.PropertyType;

                    if (value == null)
                    {
                        LogWriter.Debug("[null]");
                    }
                }
            }

            if (property != null)
            {
                return(returnType);
            }
            //return Convert.ChangeType(value, property.PropertyType);
            //return Convert.ChangeType(property.GetValue(value, null), property.PropertyType);
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Disposes the mock diagnostic system.
        /// </summary>
        public virtual void DisposeMockDiagnostics()
        {
            if (EnableTestLogging)
            {
                FixtureLogGroup.Dispose();
                FixtureLogGroup = null;

                DisposeLogging();
            }

            DiagnosticState.Dispose();

            ReportLogs();
        }
예제 #10
0
        /// <summary>
        /// Starts a new log group.
        /// </summary>
        /// <param name="summary"></param>
        /// <param name="logLevel"></param>
        /// <param name="callingMethod"></param>
        /// <returns></returns>
        static public LogGroup Start(string summary, LogLevel logLevel, MethodBase callingMethod)
        {
            LogGroup newGroup = null;

            // Create the log group even if not enabled
            newGroup = new LogGroup(summary, callingMethod, logLevel);

            // Only set the parent if the new group is enabled
            if (callingMethod != null && new LogSupervisor().IsEnabled(callingMethod.DeclaringType.Name, logLevel))
            {
                newGroup.Parent = DiagnosticState.CurrentGroup;
            }

            newGroup.Start();

            return(newGroup);
        }
예제 #11
0
        /// <summary>
        /// Gets the ID of the parent but skips any groups not marked to be output.
        /// </summary>
        public LogGroup GetOutputParent(LogGroup group)
        {
            if (group != null)
            {
                LogGroup parent = group.Parent;

                if (parent != null && !parent.IsOutput)
                {
                    parent = GetOutputParent(parent);
                }

                return(parent);
            }
            else
            {
                return(null);
            }
        }
예제 #12
0
        /// <summary>
        /// Checks wether the provided log group has a parent with the specified ID.
        /// </summary>
        /// <param name="logGroup"></param>
        /// <param name="parentID"></param>
        /// <returns></returns>
        public bool HasParent(LogGroup logGroup, Guid parentID)
        {
            if (logGroup == null)
                throw new ArgumentNullException("logGroup");

            bool hasParent = false;

            LogGroup l = logGroup;

            while (l != null && hasParent == false)
            {
                if (l != null && l.ID == parentID)
                    hasParent = true;

                l = l.Parent;
            }

            return hasParent;
        }
예제 #13
0
        /// <summary>
        /// Gets the ID of the parent but skips any groups not marked to be output.
        /// </summary>
        public Guid GetOutputParentID()
        {
            LogGroup parent         = Parent;
            Guid     outputParentID = ParentID;

            if (parent != null && !parent.IsOutput)
            {
                parent = GetOutputParent(parent);
            }

            if (parent != null)
            {
                outputParentID = parent.ID;
            }
            else
            {
                outputParentID = Guid.Empty;
            }

            return(outputParentID);
        }
예제 #14
0
        static public void SetPropertyValue(object obj, string propertyName, object value)
        {
            PropertyInfo property = null;
            object       parent   = obj;

            using (LogGroup logGroup = LogGroup.Start("Setting value of property '" + propertyName + "' on type '" + obj.GetType() + "'.", LogLevel.Debug))
            {
                string[] parts = propertyName.Split('.');

                foreach (string part in parts)
                {
                    LogWriter.Debug("Stepping to property '" + part + "'.");
                    LogWriter.Debug("Value type: '" + (value == null ? "[null]" : value.GetType().ToString()) + "'.");

                    property = parent.GetType().GetProperty(part);

                    if (property.CanWrite)
                    {
                        if (property == null)
                        {
                            throw new ArgumentException("The property '" + part + "' wasn't found on the type '" + value.GetType().ToString() + "'.");
                        }

                        LogWriter.Debug("Property type: " + property.PropertyType.FullName);

                        // If it's the last part then set the value
                        if (Array.IndexOf(parts, part) == parts.Length - 1)
                        {
                            property.SetValue(parent, value, null);
                        }
                        // Otherwise step down a level
                        else
                        {
                            parent = property.GetValue(parent, null);
                        }
                    }
                }
            }
        }
예제 #15
0
        /// <summary>
        /// Checks wether the provided log group has a parent with the specified ID.
        /// </summary>
        /// <param name="logGroup"></param>
        /// <param name="parentID"></param>
        /// <returns></returns>
        public bool HasParent(LogGroup logGroup, Guid parentID)
        {
            if (logGroup == null)
            {
                throw new ArgumentNullException("logGroup");
            }

            bool hasParent = false;

            LogGroup l = logGroup;

            while (l != null && hasParent == false)
            {
                if (l != null && l.ID == parentID)
                {
                    hasParent = true;
                }

                l = l.Parent;
            }

            return(hasParent);
        }
예제 #16
0
 public void Append(LogGroup group)
 {
     List<LogGroup> list = new List<LogGroup>();
     list.Add(group);
     SubGroups = list.ToArray();
 }
예제 #17
0
        /// <summary>
        /// Gets the ID of the parent but skips any groups not marked to be output.
        /// </summary>
        public LogGroup GetOutputParent(LogGroup group)
        {
            if (group != null)
            {
                LogGroup parent = group.Parent;

                if (parent != null && !parent.IsOutput)
                    parent = GetOutputParent(parent);

                return parent;
            }
            else
                return null;
        }
예제 #18
0
 static public LogGroup StartGroup(string summary, LogLevel logLevel, MethodBase callingMethod)
 {
     return(LogGroup.Start(summary, logLevel, callingMethod));
 }
예제 #19
0
 static public LogGroup StartGroup(string summary, LogLevel logLevel)
 {
     return(LogGroup.Start(summary, logLevel));
 }
예제 #20
0
 static public LogGroup StartGroup(string summary)
 {
     return(LogGroup.Start(summary));
 }
예제 #21
0
        /// <summary>
        /// Gets the ID of the parent but skips any groups not marked to be output.
        /// </summary>
        public Guid GetOutputParentID()
        {
            LogGroup parent = Parent;
            Guid outputParentID = ParentID;

            if (parent != null && !parent.IsOutput)
            {
                parent = GetOutputParent(parent);
            }

            if (parent != null)
                outputParentID = parent.ID;
            else
                outputParentID = Guid.Empty;

            return outputParentID;
        }
예제 #22
0
        /// <summary>
        /// Starts a new log group.
        /// </summary>
        /// <param name="summary"></param>
        /// <param name="logLevel"></param>
        /// <param name="callingMethod"></param>
        /// <returns></returns>
        public static LogGroup Start(string summary, LogLevel logLevel, MethodBase callingMethod)
        {
            LogGroup newGroup = null;

            // Create the log group even if not enabled
            newGroup = new LogGroup(summary, callingMethod, logLevel);

            // Only set the parent if the new group is enabled
            if (callingMethod != null && new LogSupervisor().IsEnabled(callingMethod.DeclaringType.Name, logLevel))
            {
                newGroup.Parent = DiagnosticState.CurrentGroup;
            }

            newGroup.Start();

            return newGroup;
        }
        /// <summary>
        /// Initializes the mock diagnostic system.
        /// </summary>
        public virtual void InitializeMockDiagnostics()
        {
            if (EnableTestLogging)
            {
                InitializeLogging();

                // Create a log group for the test
                FixtureLogGroup = LogGroup.Start("Starting test '" + TestName + "'.", LogLevel.Info);

                // Enable debug logging during testing
                LogSettingsManager.Current.Defaults["Debug"] = new ModeDetector().IsDebug;
            }
        }