Exemple #1
0
        public static void AddExecutionDetailsToLog(eExecutionPhase objExecutionPhase, string objType, string objName, object obj)
        {
            if (Reporter.AppLoggingLevel == eAppReporterLoggingLevel.Debug || Reporter.ReportAllAlsoToConsole == true)//needed for not derlling the objects if not needed to be reported
            {
                string prefix = string.Empty;

                StringBuilder stringBuilder = new StringBuilder();
                switch (objExecutionPhase)
                {
                case eExecutionPhase.Start:
                    stringBuilder.Append("--> ").Append(objType + " Execution Started");
                    break;

                case eExecutionPhase.End:
                    stringBuilder.Append("<-- ").Append(objType + " Execution Ended");
                    break;
                }
                stringBuilder.Append(": '").Append(objName).Append("'").AppendLine();

                //get the execution fields and their values
                if (objExecutionPhase == eExecutionPhase.End && obj != null)
                {
                    stringBuilder.Append("Details:").AppendLine();
                    try
                    {
                        PropertyInfo[] props = obj.GetType().GetProperties();
                        foreach (PropertyInfo prop in props)
                        {
                            try
                            {
                                FieldParamsFieldType attr = ((FieldParamsFieldType)prop.GetCustomAttribute(typeof(FieldParamsFieldType)));
                                if (attr == null)
                                {
                                    continue;
                                }
                                FieldsType ftype = attr.FieldType;
                                if (ftype == FieldsType.Field)
                                {
                                    string propName     = prop.Name;
                                    string propFullName = ((FieldParamsNameCaption)prop.GetCustomAttribute(typeof(FieldParamsNameCaption))).NameCaption;
                                    object propVal      = prop.GetValue(obj);//obj.GetType().GetProperty(propName, BindingFlags.Public | BindingFlags.Instance).GetValue(obj).ToString();
                                    string propValue;
                                    if (propVal != null)
                                    {
                                        propValue = propVal.ToString();
                                    }
                                    else
                                    {
                                        propValue = "";
                                    }

                                    stringBuilder.Append(propFullName).Append("= ").Append(propValue).AppendLine();
                                }
                            }
                            catch (Exception) { }
                        }
                    }
                    catch (Exception) { }
                }

                Reporter.ToLog(eLogLevel.DEBUG, stringBuilder.ToString());
            }
        }
        public static void AddExecutionDetailsToLog(eExecutionPhase objExecutionPhase, string objType, string objName, object obj)
        {
            if (WorkSpace.Instance != null && WorkSpace.Instance.RunningInExecutionMode || Reporter.AppLoggingLevel == eAppReporterLoggingLevel.Debug || Reporter.ReportAllAlsoToConsole == true)//needed for not derlling the objects if not needed to be reported
            {
                string prefix = string.Empty;

                StringBuilder stringBuilder = new StringBuilder();
                switch (objExecutionPhase)
                {
                case eExecutionPhase.Start:
                    stringBuilder.Append("--> ").Append(objType + " Execution Started");
                    break;

                case eExecutionPhase.End:
                    stringBuilder.Append("<-- ").Append(objType + " Execution Ended");
                    break;
                }
                stringBuilder.Append(": '").Append(objName).Append("'").AppendLine();

                //get the execution fields and their values
                if (objExecutionPhase == eExecutionPhase.End && obj != null)
                {
                    stringBuilder.Append("Details:").AppendLine();
                    try
                    {
                        PropertyInfo[] props = obj.GetType().GetProperties();
                        foreach (PropertyInfo prop in props)
                        {
                            try
                            {
                                FieldParamsFieldType attr = ((FieldParamsFieldType)prop.GetCustomAttribute(typeof(FieldParamsFieldType)));
                                if (attr == null)
                                {
                                    continue;
                                }
                                FieldsType ftype = attr.FieldType;
                                if (ftype == FieldsType.Field)
                                {
                                    string propName     = prop.Name;
                                    string propFullName = ((FieldParamsNameCaption)prop.GetCustomAttribute(typeof(FieldParamsNameCaption))).NameCaption;
                                    object propValueobj = prop.GetValue(obj);//obj.GetType().GetProperty(propName, BindingFlags.Public | BindingFlags.Instance).GetValue(obj).ToString();
                                    string propValueStr = "";
                                    if (propValueobj != null)
                                    {
                                        //special case for execution time convertion from UTC format
                                        if (Attribute.IsDefined(prop, typeof(UsingUTCTimeFormat)))
                                        {
                                            try
                                            {
                                                propValueStr = ((DateTime)propValueobj).ToLocalTime().ToString("dd-MMM-yy HH:mm:ss");
                                            }
                                            catch
                                            {
                                                propValueStr = propValueobj.ToString();
                                            }
                                        }
                                        else
                                        {
                                            propValueStr = propValueobj.ToString();
                                        }
                                    }

                                    stringBuilder.Append(propFullName).Append("= ").Append(propValueStr).AppendLine();
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    catch (Exception) { }
                }

                if (WorkSpace.Instance.RunningInExecutionMode || Reporter.ReportAllAlsoToConsole == true)
                {
                    Reporter.ToLog(eLogLevel.INFO, stringBuilder.ToString());
                }
                else
                {
                    Reporter.ToLog(eLogLevel.DEBUG, stringBuilder.ToString());
                }
            }
        }