Exemplo n.º 1
0
        /// <summary>
        /// Write errors in log file, using Errors singleton class
        /// that contains all catched errors since the last writting
        /// <Error>
        ///   <AppError>
        ///     <Date></Date>
        ///     <Message ErrorId="n">...</Message>
        ///   </AppError>
        /// </Error>
        /// </summary>
        public void LogError()
        {
            String    uri    = CreateFileIfNotExist();
            XDocument doc    = XDocument.Load(uri);
            XElement  erNode = doc.Root.Element("Error");
            string    time   = DateTime.UtcNow.ToString("MM/dd/yyyy HH:mm:ss");

            foreach (Error e in Errors.GetErrorsToLog())
            {
                XElement error = new XElement("AppError");

                logParameter(error, new Parameter("Date", null, time));

                XElement message = new XElement("Message", e.Message);

                if (Errors.ShowId &&
                    e.Id > -1)
                {
                    addAtrribute(message, "ErrorId", e.Id.ToString());
                }

                if (e.Port > 1)
                {
                    addAtrribute(message, "Port", e.Port.ToString());
                }

                error.Add(message);

                erNode.Add(error);
            }

            doc.Save(uri);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Write errors in log file, using Errors singleton class
        /// that contains all catched errors since the last writting
        /// <Error>
        ///   <AppError>
        ///     <Date></Date>
        ///     <Message ErrorId="n">...</Message>
        ///   </AppError>
        /// </Error>
        /// </summary>
        public string Error()
        {
            String    uri     = CreateFileIfNotExist();
            XDocument doc     = XDocument.Load(uri);
            XElement  element = doc.Root.Element("Error");
            string    time    = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");

            // The log send to the explorer should be only the last error performed, not full current activity log
            string    uriLog = this.CreateLogBase_Scripting_Error();
            XDocument docLog = XDocument.Load(uriLog);

            XElement error;
            XElement message;

            foreach (Error e in Errors.GetErrorsToLog())
            {
                error = new XElement("AppError");

                Parameter(error, new Parameter("Date", null, time));

                message = new XElement("Message", e.Message);

                if (Errors.ShowId &&
                    e.Id > -1)
                {
                    AddAtrribute(message, "ErrorId", e.Id.ToString());
                }

                if (e.Port > 1)
                {
                    AddAtrribute(message, "Port", e.Port.ToString());
                }

                error.Add(message);

                element.Add(error);        // Activity log
                docLog.Root.Add(error);    // Result ( send to explorer )
            }

            doc.Save(uri);

            // Only for the result log
            element = new XElement("AppMessage");
            Parameter(element, new Parameter("Date", null, time));
            message = new XElement("Message");
            element.Add(message);
            docLog.Root.Add(element);

            string docLogText = docLog.ToString();

            if (File.Exists(uriLog))
            {
                File.Delete(uriLog);
            }

            return(docLogText);
        }