Esempio n. 1
0
 public static void WriteErrorLog(String logText)
 {
     if (ErrorLogFileWriter != null)
     {
         ErrorLogFileWriter.Write(logText);
     }
 }
Esempio n. 2
0
        public void FilenameIsCreatedCorrectly()
        {
            var now  = DateTime.Now;
            var root = Path.GetDirectoryName(typeof(LogFileWriter).Assembly.Location);
            var name = String.Format("WSM-{0}-{1:D2}-{2:D2}.log", now.Year, now.Month, now.Day);
            var path = Path.Combine(root, name);

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

            Target.Write("It's all in the pie. {0}", Math.PI);

            Assert.IsTrue(File.Exists(path), "Log file not found after creating.");
            Assert.AreEqual
            (
                "It's all in the pie. 3.14159265358979",
                File.ReadAllLines(path)[0]
            );

            File.Delete(path);
        }
Esempio n. 3
0
        private void btnSaveSelected_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog dlgSave = new SaveFileDialog())
            {
                dlgSave.Filter = "Log File (Compressed)|*.logz";

                if (dlgSave.ShowDialog() == DialogResult.OK)
                {
                    using (var fileWriter = new LogFileWriter(dlgSave.FileName))
                    {
                        foreach (DataRow row in m_dataTable.Rows)
                        {
                            LogMessage message = row["Object"] as LogMessage;
                            bool       shown   = (bool)row["_Show"];

                            if (shown)
                            {
                                fileWriter.Write(message, false);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        public void AppendOutputFile(string text)
        {
            if (text == null)
            {
                text = String.Empty;
            }

            if (!File.Exists(LogFile))
            {
                var dir = Path.GetDirectoryName(LogFile);

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

            if (LogFileWriter == null)
            {
                OpenLogFileWriter();
            }

            LogFileWriter.Write(text);
        }
Esempio n. 5
0
        public void TrackEventLogFileTest()
        {
            IWorkContext context    = WorkContext.Empty;
            string       tempFolder = Path.Combine(Path.GetTempPath(), "TelemetryTest");

            Directory.CreateDirectory(tempFolder);
            string logFileName;

            using (var logWriter = new LogFileWriter(tempFolder).Open())
                using (EventRouter router = new EventRouter(context).Register("test", (x, _) => logWriter.Write(x)))
                {
                    logFileName = logWriter.LogFileName;

                    TrackEventSource source = new TrackEventSource(router, "test");

                    source.Verbose(context, "first message");
                }

            var readList = new List <EventData>();

            using (var reader = new LogFileReader(logFileName).Open())
            {
                while (true)
                {
                    IEnumerable <EventData> readItems = reader.Read(100);
                    readItems.Should().NotBeNull();
                    if (!readItems.Any())
                    {
                        break;
                    }

                    readList.AddRange(readItems);
                }
            }

            readList.Count.Should().Be(1);

            EventData eventData = readList[0];

            eventData.EventSourceName.Should().Be("test");
            eventData.EventName.Should().Be("Verbose");
            eventData.TelemetryLevel.Should().Be(TelemetryLevel.Verbose);
            eventData.Cv.Should().Be(context.Cv.ToString());
            eventData.Tag.Should().Be(context.Tag.ToString());
        }
Esempio n. 6
0
        public void MultipleTrackEventLogFileTest()
        {
            IWorkContext context    = WorkContext.Empty;
            string       tempFolder = Path.Combine(Path.GetTempPath(), "TelemetryTest");

            Directory.CreateDirectory(tempFolder);
            string logFileName;

            using (var logWriter = new LogFileWriter(tempFolder).Open())
            {
                logFileName = logWriter.LogFileName;

                EventRouter router = new EventRouter(context)
                                     .Register("test", (x, _) => logWriter.Write(x));

                TrackEventSource source = new TrackEventSource(router, "test");

                Enumerable.Range(0, 100).Run(x =>
                {
                    source.Verbose(context, $"{x}_verbose message");
                    source.Info(context, $"{x}_info message");
                    source.Critical(context, $"{x}_critical message");
                });

                Thread.Sleep(TimeSpan.FromSeconds(1));
            }

            var readList = new List <EventData>();

            using (var reader = new LogFileReader(logFileName).Open())
            {
                while (true)
                {
                    IEnumerable <EventData> readItems = reader.Read(500);
                    readItems.Should().NotBeNull();
                    if (!readItems.Any())
                    {
                        break;
                    }

                    readList.AddRange(readItems);
                }
            }

            readList.Count.Should().Be(300);

            IEnumerator <EventData> dataEnumerable = readList.GetEnumerator();

            Enumerable.Range(0, 100).Run(x =>
            {
                EventData ev;

                dataEnumerable.MoveNext().Should().BeTrue();
                ev = dataEnumerable.Current;
                ev.EventSourceName.Should().Be("test");
                ev.EventName.Should().Be("Verbose");
                ev.TelemetryLevel.Should().Be(TelemetryLevel.Verbose);
                ev.Cv.Should().Be(context.Cv.ToString());
                ev.Tag.Should().Be(context.Tag.ToString());
                ev.Message.Should().Be($"{x}_verbose message");

                dataEnumerable.MoveNext().Should().BeTrue();
                ev = dataEnumerable.Current;
                ev.EventSourceName.Should().Be("test");
                ev.EventName.Should().Be("Info");
                ev.TelemetryLevel.Should().Be(TelemetryLevel.Informational);
                ev.Cv.Should().Be(context.Cv.ToString());
                ev.Tag.Should().Be(context.Tag.ToString());
                ev.Message.Should().Be($"{x}_info message");

                dataEnumerable.MoveNext().Should().BeTrue();
                ev = dataEnumerable.Current;
                ev.EventSourceName.Should().Be("test");
                ev.EventName.Should().Be("Critical");
                ev.TelemetryLevel.Should().Be(TelemetryLevel.Critical);
                ev.Cv.Should().Be(context.Cv.ToString());
                ev.Tag.Should().Be(context.Tag.ToString());
                ev.Message.Should().Be($"{x}_critical message");
            });
        }