Exemple #1
0
        /// <summary>
        /// Salva os dados de log, que são armazenados em banco de dados, em arquivo xml Se ocorrer falha de acesso ao banco de dados
        /// </summary>
        /// <param name="LoggerData">O objeto Logger Contendo as mesmas informações que vão para a tabela de log</param>k
        public static void SaveLoggerData(LoggerData LoggerData)
        {
            string sSource;
            string sLog;
            string sEvent;

            string path = string.Format(@"{0}LogSystem", AppDomain.CurrentDomain.BaseDirectory);
            Serializer <LoggerData> SerializerObj = new Serializer <LoggerData>();
            string XmlDocumentName = string.Format("log_application_sap_{0}.xml", DateTime.Now.ToString("dd_MM_yyyy__hh_MM_ss"));

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            XmlDocument XDoc = new XmlDocument();

            XDoc.InnerXml = SerializerObj.SerializeObject(LoggerData);
            try
            {
                XDoc.Save(string.Format(@"{0}\{1}", path, XmlDocumentName));
            }
            catch (Exception Ex)
            {
                sSource = "SB1Util Exeption";
                sLog    = "Ação com dados ";
                sEvent  = Ex.Message;

                if (!EventLog.SourceExists(sSource))
                {
                    EventLog.CreateEventSource(sSource, sLog);
                }

                EventLog.WriteEntry(sSource, sEvent);
                EventLog.WriteEntry(sSource, sEvent,
                                    EventLogEntryType.Warning, 234);
            }
        }
Exemple #2
0
        /// <summary>
        /// Salva o log em banco de dados. Caso ocorra falha, o log será gerado no diretório raiz, dentro do diretório LogSystem
        /// </summary>
        /// <param name="text">A mensagem da exceção</param>
        /// <param name="type">O tipo de exceção</param>
        private void printText(string text, LogType type)
        {
            DateTime   dt            = DateTime.Now;
            LoggerData LoggerDataObj = null;
            string     Time          = String.Format("{0:HH:mm:ss}", dt);

            try
            {
                LoggerDataObj = new LoggerData();
                string form = "";
                if (DBFacade.getInstance().Connection.App.Forms.ActiveForm != null)
                {
                    try
                    {
                        form = DBFacade.getInstance().Connection.App.Forms.ActiveForm.TypeEx;
                    }
                    catch (Exception e)
                    {
                        form = "";
                    }
                }


                UserTable table = DBFacade.getInstance().getUserTable("SB1_ADDON_LOG");
                table.Code = "" + (dt.Ticks + 1);
                table.Name = "" + (dt.Ticks + 1);

                //Ajusta valores nos campos pois pode ocorrer exception caso esteja NULL
                addonVersion   = addonVersion == null ? "" : addonVersion;
                addonName      = addonName == null ? "" : addonName;
                companyVersion = companyVersion == null ? "" : companyVersion;
                libVersion     = libVersion == null ? "" : libVersion;
                type           = type == null ? LogType.INFO : type;
                text           = text == null ? "" : text;

                table.UserFields.Fields.Item("U_AddonVersion").Value   = addonVersion;
                table.UserFields.Fields.Item("U_AddonName").Value      = addonName;
                table.UserFields.Fields.Item("U_CompanyVersion").Value = companyVersion;
                table.UserFields.Fields.Item("U_Date").Value           = dt;
                table.UserFields.Fields.Item("U_LibVersion").Value     = libVersion;
                table.UserFields.Fields.Item("U_LogType").Value        = type.ToString();
                table.UserFields.Fields.Item("U_Text").Value           = text;
                table.UserFields.Fields.Item("U_Time").Value           = Time;
                table.UserFields.Fields.Item("U_User").Value           = user;
                table.UserFields.Fields.Item("U_FormID").Value         = form;
                table.UserFields.Fields.Item("U_XMLException").Value   = "";
                table.UserFields.Fields.Item("U_Operation").Value      = (opStack.Count == 0 ? "" : opStack.Peek());

                table.Add();
                table = null;

                LoggerDataObj.U_AddonVersion   = addonVersion;
                LoggerDataObj.U_CompanyVersion = companyVersion;
                LoggerDataObj.U_Date           = dt;
                LoggerDataObj.U_LibVersion     = libVersion;
                LoggerDataObj.U_LogType        = type.ToString();
                LoggerDataObj.U_Text           = text;
                LoggerDataObj.U_Time           = Time;
                LoggerDataObj.U_User           = user;
            }
            catch (Exception e)
            {
                LogManager.SaveLoggerData(LoggerDataObj);
                SB1ControlException.SB1ControlException.Save(e);
                //B1Connection.getInstance().App.SetStatusBarMessage("Erro ao escrever Log: " + e.Message, SAPbouiCOM.BoMessageTime.bmt_Long);
            }
        }