Esempio n. 1
0
        /// <summary>
        /// Write to log
        /// </summary>
        /// <param name="msg">Message</param>
        /// <param name="label">Label</param>
        public void Write(string msg, string label)
        {
            var evArgs = new LogArgs(msg, label);

            RaiseOnWrite(evArgs);
            if (!evArgs.Cancel)
            {
                Push(evArgs);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Write to log from thread
        /// </summary>
        private void __WriteToLog(object o)
        {
            LogArgs args  = (LogArgs)o;
            string  label = args.Label;

            if (!String.IsNullOrEmpty(label))
            {
                label = String.Concat(label, " ");
            }
            else
            {
                label = String.Empty;
            }

            if (args.Message != null && args.Message.Length > 0)
            {
                string logLine = String.Concat(label, "[", args.Time.ToString("dd MMM yyyy HH:mm:ss\\.fff"), "] ", args.Message, Environment.NewLine);

                try
                {
                    if (!File.Exists(lastFile))
                    {
                        Directory.CreateDirectory(Settings.LogFolderPath);
                    }

                    if (!String.IsNullOrEmpty(lastFile))
                    {
                        FileInfo lf = new FileInfo(lastFile);
                        if (lf.Exists && lf.Length > Settings.MaxFileSizeInBytes)
                        {
                            lastFile = GetNewFileName();
                        }
                    }
                    else
                    {
                        lastFile = GetNewFileName();
                    }

                    using (var fileStream = new StreamWriter(lastFile, true, Encoding))
                        fileStream.Write(logLine);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("FATAL: Write log to file!\n" + ex);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Raises before write log
 /// </summary>
 protected virtual void RaiseOnWrite(LogArgs evArgs)
 {
     OnWrite(this, evArgs);
 }
Esempio n. 4
0
 /// <summary>
 /// Push log to process
 /// </summary>
 /// <param name="o">Logger args</param>
 private void Push(LogArgs o)
 {
     Queue.Enqueue(o);
     LogResetEvent.Set();
 }