Example #1
0
        public static void Log(LogMessageTypes type, string msg, string targetSite, string trace)
        {
            if (string.IsNullOrEmpty(LogFilePath))
            {
                return;
            }

            var       dateAndTime = DateTime.Now.ToString(CultureInfo.InvariantCulture);
            XDocument xdoc;

            //Replace this portion with a command in options view for example to clear the log file if is exceeds a certin size.
            //if (File.Exists(LogFilePath))
            //{
            //    var info = new FileInfo(LogFilePath);
            //    var length = info.Length;
            //    if (length >= MaxFileSize)
            //    {
            //        info.Delete();
            //        Log(type, msg, targetSite, trace);
            //    }

            //}
            if (File.Exists(LogFilePath))
            {
                xdoc = XDocument.Load(LogFilePath);
                var xElement = xdoc.Element("Logs");
                if (xElement != null)
                {
                    xElement.Add(
                        new XElement("Log",
                                     new XElement("DateAndTime", dateAndTime),
                                     new XElement("Type", type.ToString()),
                                     new XElement("Message", msg),
                                     new XElement("TargetSite", targetSite),
                                     new XElement("Tarce", trace)

                                     ));
                }
            }
            else
            {
                xdoc = new XDocument(
                    new XElement("Logs",
                                 new XElement("Log",
                                              new XElement("DateAndTime", dateAndTime),
                                              new XElement("Type", type.ToString()),
                                              new XElement("Message", msg),
                                              new XElement("TargetSite", targetSite),
                                              new XElement("Tarce", trace)

                                              )));
            }

            xdoc.Save(LogFilePath);
        }
Example #2
0
        public void Add(int?builderId, int?buildingId, int?chunkId, LogMessageTypes type, string message)
        {
            const string query =
                "INSERT INTO [Log] ([ChunkId],[BuilderId],[BuildingId],[Type],[Time],[Message]) VALUES (@chunkId, @builderId, @buildingId, @type, @time, @message)";

            using (var connection = SqlConnectionHelper.OpenMssqlConnection(_connectionString))
                using (var cmd = new SqlCommand(query, connection)
                {
                    CommandTimeout = 0
                })
                {
                    cmd.Parameters.Add("@chunkId", SqlDbType.Int);
                    cmd.Parameters["@chunkId"].Value = chunkId.HasValue ? chunkId : (object)DBNull.Value;

                    cmd.Parameters.Add("@builderId", SqlDbType.Int);
                    cmd.Parameters["@builderId"].Value = builderId.HasValue ? builderId : (object)DBNull.Value;

                    cmd.Parameters.Add("@buildingId", SqlDbType.Int);
                    cmd.Parameters["@buildingId"].Value = buildingId.HasValue ? buildingId : (object)DBNull.Value;

                    cmd.Parameters.Add("@type", SqlDbType.VarChar);
                    cmd.Parameters["@type"].Value = type.ToString();

                    cmd.Parameters.Add("@time", SqlDbType.DateTime);
                    cmd.Parameters["@time"].Value = DateTime.Now;

                    cmd.Parameters.Add("@message", SqlDbType.VarChar);
                    cmd.Parameters["@message"].Value = message;

                    cmd.ExecuteNonQuery();
                }
        }
Example #3
0
        public void Add(int? builderId, int? buildingId, int? chunkId, LogMessageTypes type, string message)
        {
            const string query =
             "INSERT INTO [Log] ([ChunkId],[BuilderId],[BuildingId],[Type],[Time],[Message]) VALUES (@chunkId, @builderId, @buildingId, @type, @time, @message)";

             using (var connection = SqlConnectionHelper.OpenConnection(connectionString))
             using (var cmd = new SqlCommand(query, connection) { CommandTimeout = 0 })
             {
            cmd.Parameters.Add("@chunkId", SqlDbType.Int);
            cmd.Parameters["@chunkId"].Value = chunkId.HasValue ? chunkId : (object)DBNull.Value;

            cmd.Parameters.Add("@builderId", SqlDbType.Int);
            cmd.Parameters["@builderId"].Value = builderId.HasValue ? builderId : (object)DBNull.Value;

            cmd.Parameters.Add("@buildingId", SqlDbType.Int);
            cmd.Parameters["@buildingId"].Value = buildingId.HasValue ? buildingId : (object)DBNull.Value;

            cmd.Parameters.Add("@type", SqlDbType.VarChar);
            cmd.Parameters["@type"].Value = type.ToString();

            cmd.Parameters.Add("@time", SqlDbType.DateTime);
            cmd.Parameters["@time"].Value = DateTime.Now;

            cmd.Parameters.Add("@message", SqlDbType.VarChar);
            cmd.Parameters["@message"].Value = message;

            cmd.ExecuteNonQuery();
             }
        }
Example #4
0
        /// <summary>
        /// This method will create automaticly.
        /// Log file in folder with staic path.
        /// Every new day will be create a one new file.
        /// </summary>
        /// <param name="LogSource">Who send this message log.</param>
        /// <param name="MessageText">Concreet message.</param>
        public void CreateRecord(string LogSource, string MessageText, LogMessageTypes MessageType, bool EndOfLogs = false)
        {
            // Write LOG record to the message buffer if is enabled.
            if (Enable)
            {
                // Structre of the message.
                // LogSource\tYear.Month.Day/Hour:Minute:Seconds.Miliseconds\tType\tMessageText
                string dateAndTime = DateTime.Now.ToString("yyyy.MM.dd/HH:mm:ss.fff", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                string message = LogSource + "\t" + dateAndTime + "\t" + MessageType.ToString() + "\t" + MessageText;

                // Add message to the message buffer.
                this.logMessages.Add(message);

                // Write end of log line
                if(EndOfLogs)
                {
                    this.logMessages.Add("\r\n===================================================================================\r\n");
                }

                // If filr are critical count, just write it to a file.
                if ((this.logMessages.Count > this.colectionSize) || EndOfLogs)
                {
                    this.WtriteToLogFile();
                }
            }
        }
Example #5
0
        /// <summary>
        /// This method will create automaticly.
        /// Log file in folder with staic path.
        /// Every new day will be create a one new file.
        /// </summary>
        /// <param name="LogSource">Who send this message log.</param>
        /// <param name="MessageText">Concreet message.</param>
        public static void CreateRecord(string LogSource, string MessageText, LogMessageTypes MessageType, bool EndOfLogs = false)
        {
            // Write LOG record to the message buffer if is enabled.
            if (Enable)
            {
                // Structre of the message.
                // LogSource\tYear.Month.Day/Hour:Minute:Seconds.Miliseconds\tType\tMessageText
                string dateAndTime = DateTime.Now.ToString("yyyy.MM.dd/HH:mm:ss.fff", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                string message     = LogSource + "\t" + dateAndTime + "\t" + MessageType.ToString() + "\t" + MessageText;

                // Add message to the message buffer.
                Messages.Add(message);

                // Write end of log line
                if (EndOfLogs)
                {
                    Messages.Add("\r\n===================================================================================\r\n");
                }

                // If filr are critical count, just write it to a file.
                if ((Messages.Count > MessageColectionSize) || EndOfLogs)
                {
                    Log.WtriteToLogFile();
                }

                /*
                 * if ((MessageType == LogMessageTypes.ERROR) && EnableBeep)
                 * {
                 *  Console.Beep(5000, 20);
                 * }
                 */
            }
        }
Example #6
0
        public static void Log(LogMessageTypes type, string msg, string targetSite, string trace)
        {
            string    dateAndTime = DateTime.Now.ToString();
            XDocument xdoc        = null;

            if (File.Exists(_filePath))
            {
                FileInfo info   = new FileInfo(_filePath);
                var      length = info.Length;
                if (length >= MaxFileSize)
                {
                    info.Delete();
                    Log(type, msg, targetSite, trace);
                }
            }
            if (File.Exists(_filePath))
            {
                xdoc = XDocument.Load(_filePath);
                xdoc.Element("Logs").Add(
                    new XElement("Log",
                                 new XElement("DateAndTime", dateAndTime),
                                 new XElement("Type", type.ToString()),
                                 new XElement("Message", msg),
                                 new XElement("TargetSite", targetSite),
                                 new XElement("Tarce", trace)

                                 ));
            }
            else
            {
                xdoc = new XDocument(
                    new XElement("Logs",
                                 new XElement("Log",
                                              new XElement("DateAndTime", dateAndTime),
                                              new XElement("Type", type.ToString()),
                                              new XElement("Message", msg),
                                              new XElement("TargetSite", targetSite),
                                              new XElement("Tarce", trace)

                                              )));
            }

            xdoc.Save(_filePath);
        }
Example #7
0
 public static string GetFirstLetter(this LogMessageTypes messageType)
 {
     return(messageType.ToString().Substring(0, 1).ToUpper());
 }
Example #8
0
        public void Write(LogMessageTypes type, string str)
        {
            DebugConsole.Instance.Write(type, str); // also forward the log request to debug-console.
            if (!this._loggerEnabled) return;

            this._logStream.WriteLine(string.Format("[{0}][{1}]: {2}", DateTime.Now.ToString("HH:mm:ss"), type.ToString().PadLeft(5), str));
            this._logStream.AutoFlush = true;
        }