Example #1
0
        /// <summary>
        /// Schreibt angegebene LogEntry in die Logdatei.
        /// </summary>
        /// <param name="entry">Enthält alle Infos </param>
        /// <param name="instance"></param>
        /// <returns></returns>
        private static bool WriteLog(LogEntry entry, int instance)
        {
            entry.Prepare(instance);

            if (!entry.EventFired)
            {
                try
                {
                    LineWritten?.Invoke(entry.Log);
                }
                catch { }
                entry.EventFired = true;
            }

            FileInfo fi = Globals.GetLogfile();

            if (fi == null)
            {
                return(false);
            }

            using (FileStream fs = new FileStream(fi.FullName, FileMode.OpenOrCreate))
            {
                fs.Seek(0, SeekOrigin.End);
                fs.Write(entry.LogData, 0, entry.LogData.Length);
            }

            return(true);
        }
Example #2
0
        public override void Write(char value)
        {
            _builder.Append(value);
            // check if we end with New Line
            var newLineLength = Environment.NewLine.Length;

            if (_builder.Length < newLineLength)
            {
                return;
            }

            // newLineLength or more characters exist, check the last #newLineLength characters and see if they are equal.
            bool equal = true;

            for (int i = 0, j = _builder.Length - newLineLength; i < newLineLength; i++, j++)
            {
                if (Environment.NewLine[i] != _builder[j])
                {
                    equal = false;
                    break;
                }
            }

            if (equal)
            {
                // new line detected, invoke eventhandler with string
                var line = _builder.ToString(0, _builder.Length - newLineLength);
                LineWritten?.Invoke(this, new LineWrittenEventArgs(line));
                _builder.Clear();
            }
        }
Example #3
0
        public void WriteLine(string value)
        {
            // write a blank line if previously requested
            if (m_BlankLineRequested)
            {
                // only write blank line if document is not empty
                if (m_AnyLinesWritten)
                {
                    m_InnerWriter.WriteLine(GetBlankLinePrefix());
                }
                m_BlankLineRequested = false;
            }

            // write prefix
            m_InnerWriter.Write(GetLinePrefix());

            // write value
            m_InnerWriter.WriteLine(value);
            LineWritten?.Invoke(this, EventArgs.Empty);
            m_AnyLinesWritten = true;
        }