Exemplo n.º 1
0
            public void AddLog(string pMessage, clsGeneralSetting.Logger.En_LogDetail pLevel)
            {
                string[] strArrays = new string[] { Strings.Format(DateTime.Now, "yyyy/MM/dd HH:mm:ss"), " - ", pLevel.ToString(), " - ", pMessage };
                string   str       = string.Concat(strArrays);

                if (this.EventSource != null && (int)pLevel <= this.LogEventSourceLevel)
                {
                    if (Operators.CompareString(clsGeneralSetting.Logger.ELog.Source, "", false) == 0)
                    {
                        clsGeneralSetting.Logger.ELog.Source = this.EventSource;
                    }
                    if (!EventLog.SourceExists(clsGeneralSetting.Logger.ELog.Source))
                    {
                        EventLog.CreateEventSource(clsGeneralSetting.Logger.ELog.Source, string.Concat("Log", clsGeneralSetting.Logger.ELog.Source));
                    }
                    switch (pLevel)
                    {
                    case clsGeneralSetting.Logger.En_LogDetail.A_Erreurs_Critiques:
                    case clsGeneralSetting.Logger.En_LogDetail.B_Erreurs:
                    {
                        clsGeneralSetting.Logger.ELog.WriteEntry(pMessage, EventLogEntryType.Error);
                        break;
                    }

                    case clsGeneralSetting.Logger.En_LogDetail.C_Avertissements:
                    {
                        clsGeneralSetting.Logger.ELog.WriteEntry(pMessage, EventLogEntryType.Warning);
                        break;
                    }

                    default:
                    {
                        clsGeneralSetting.Logger.ELog.WriteEntry(pMessage, EventLogEntryType.Information);
                        break;
                    }
                    }
                }
                string str1 = Conversions.ToString(0);

                while (true)
                {
                    try
                    {
                        str1 = Conversions.ToString(Conversions.ToDouble(str1) + 1);
                        if (this.LogInFile & (int)pLevel <= this.LogInFileLevel)
                        {
                            if (!Directory.Exists(this.LogDirectory))
                            {
                                Directory.CreateDirectory(this.LogDirectory);
                            }
                            Objets.FileWrite(this.FileLogName, string.Concat(str, "\r\n"), true, false, null);
                        }
                        break;
                    }
                    catch (Exception exception1)
                    {
                        ProjectData.SetProjectError(exception1);
                        Exception exception = exception1;
                        if (Conversions.ToDouble(str1) != 1)
                        {
                            if (this.EventSource != null)
                            {
                                clsGeneralSetting.Logger.ELog.WriteEntry(string.Concat("Inscription dans le fichier de log impossible : ", exception.Message), EventLogEntryType.Warning);
                            }
                            ProjectData.ClearProjectError();
                            break;
                        }
                        else
                        {
                            Thread.Sleep(100);
                            ProjectData.ClearProjectError();
                        }
                    }
                }
                if (this.LogInMail && (int)pLevel <= this.LogInMailLevel)
                {
                    this.MailLog.Append(string.Concat(str, "\r\n"));
                }
                try
                {
                    if (this.LogInSBOTOOLS)
                    {
                        SBOTools.AddLog(pMessage, (int)pLevel);
                    }
                    if (this.LogInADO & (int)pLevel <= this.LogInADOLevel)
                    {
                        strArrays = new string[] { "begin tran\r\ndeclare @NextCode as varchar(8) ;\r\nselect @NextCode=cast(coalesce(Max(cast(Code as int)),0)+1 as varchar(8)) FROM [@MG2S_SBOTLog] updlock ; \r\nselect @NextCode=stuff('00000000',9-len(@NextCode),len(@NextCode),@NextCode) ; \r\ninsert into [@MG2S_SBOTLog] (Code,Name, U_DateTime, U_UserName,U_HostName,U_Details, U_Level) VALUES (@NextCode, @NextCode, '", Objets.StrClean(Strings.Format(DateTime.Now, "yyyy-MM-dd HH:mm:ss")), "', '", Objets.StrClean(Environment.UserName), "','", Objets.StrClean(Environment.MachineName), "','", Objets.StrClean(pMessage), "',", pLevel.ToString(), ") ;\r\ncommit" };
                        string     str2  = string.Concat(strArrays);
                        Connection aDOCN = this.ADOCN;
                        object     value = Missing.Value;
                        aDOCN.Execute(str2, out value, -1);
                    }
                }
                catch (Exception exception3)
                {
                    ProjectData.SetProjectError(exception3);
                    Exception exception2 = exception3;
                    if (this.EventSource != null)
                    {
                        clsGeneralSetting.Logger.ELog.WriteEntry(string.Concat("Inscription des logs dans SBO / ADO  impossible : ", exception2.Message), EventLogEntryType.Warning);
                    }
                    ProjectData.ClearProjectError();
                }
            }