Esempio n. 1
0
        public void Trace_AppliesLevelFilter()
        {
            DirectoryInfo directory = new DirectoryInfo(_logFilePath);

            directory.Create();

            int count = directory.EnumerateFiles().Count();

            Assert.Equal(0, count);

            FileTraceWriter traceWriter = new FileTraceWriter(_logFilePath, TraceLevel.Info);

            traceWriter.Verbose("Test Verbose");
            traceWriter.Info("Test Info");
            traceWriter.Warning("Test Warning");
            traceWriter.Error("Test Error");

            traceWriter.Flush();

            string logFile = directory.EnumerateFiles().First().FullName;
            string text    = File.ReadAllText(logFile);

            Assert.True(text.Contains("Test Error"));
            Assert.True(text.Contains("Test Warning"));
            Assert.True(text.Contains("Test Info"));
            Assert.False(text.Contains("Test Verbose"));
        }
Esempio n. 2
0
        public void WriteLogs_ReusesLastFile()
        {
            DirectoryInfo directory = new DirectoryInfo(_logFilePath);

            directory.Create();

            int count = directory.EnumerateFiles().Count();

            Assert.Equal(0, count);

            for (int i = 0; i < 3; i++)
            {
                FileTraceWriter traceWriter = new FileTraceWriter(_logFilePath, TraceLevel.Verbose);
                traceWriter.Verbose("Testing");
                traceWriter.Flush();
            }

            count = directory.EnumerateFiles().Count();
            Assert.Equal(1, count);

            string logFile = directory.EnumerateFiles().First().FullName;

            string[] fileLines = File.ReadAllLines(logFile);
            Assert.Equal(3, fileLines.Length);
        }
            private void CreateTestFunctionLogs(string logRoot, string functionName)
            {
                string          functionLogPath = Path.Combine(logRoot, functionName);
                FileTraceWriter traceWriter     = new FileTraceWriter(functionLogPath, TraceLevel.Verbose);

                traceWriter.Verbose("Test log message");
                traceWriter.Flush();
            }
Esempio n. 4
0
        private void WriteLogs(string logFilePath, int numLogs)
        {
            FileTraceWriter traceWriter = new FileTraceWriter(logFilePath, TraceLevel.Verbose);

            for (int i = 0; i < numLogs; i++)
            {
                traceWriter.Verbose(string.Format("Test message {0} {1}", Thread.CurrentThread.ManagedThreadId, i));
            }

            traceWriter.Flush();
        }
Esempio n. 5
0
        public void SetNewLogFile_EmptyDirectory_Succeeds()
        {
            DirectoryInfo directory = new DirectoryInfo(_logFilePath);

            directory.Create();

            FileTraceWriter traceWriter = new FileTraceWriter(_logFilePath, TraceLevel.Verbose);

            traceWriter.SetNewLogFile();

            var files = directory.GetFiles().OrderByDescending(p => p.LastWriteTime).ToArray();

            Assert.Equal(0, files.Length);

            traceWriter.Verbose("Test log");
            traceWriter.Flush();

            files = directory.GetFiles().OrderByDescending(p => p.LastWriteTime).ToArray();
            Assert.Equal(1, files.Length);
        }
Esempio n. 6
0
        public void Trace_WritesExpectedLogs()
        {
            DirectoryInfo directory = new DirectoryInfo(_logFilePath);

            directory.Create();

            int count = directory.EnumerateFiles().Count();

            Assert.Equal(0, count);

            FileTraceWriter traceWriter = new FileTraceWriter(_logFilePath, TraceLevel.Info);

            traceWriter.Verbose("Test Verbose");
            traceWriter.Info("Test Info");
            traceWriter.Warning("Test Warning");
            traceWriter.Error("Test Error");

            // trace a system event - expect it to be ignored
            var properties = new Dictionary <string, object>
            {
                { ScriptConstants.TracePropertyIsSystemTraceKey, true }
            };

            traceWriter.Info("Test System", properties);

            traceWriter.Flush();

            string logFile = directory.EnumerateFiles().First().FullName;
            string text    = File.ReadAllText(logFile);

            Assert.True(text.Contains("Test Error"));
            Assert.True(text.Contains("Test Warning"));
            Assert.True(text.Contains("Test Info"));
            Assert.False(text.Contains("Test Verbose"));
            Assert.False(text.Contains("Test System"));
        }
        public void SetNewLogFile_EmptyDirectory_Succeeds()
        {
            DirectoryInfo directory = new DirectoryInfo(_logFilePath);
            directory.Create();

            FileTraceWriter traceWriter = new FileTraceWriter(_logFilePath, TraceLevel.Verbose);
            traceWriter.SetNewLogFile();

            var files = directory.GetFiles().OrderByDescending(p => p.LastWriteTime).ToArray();
            Assert.Equal(0, files.Length);

            traceWriter.Verbose("Test log");
            traceWriter.Flush();

            files = directory.GetFiles().OrderByDescending(p => p.LastWriteTime).ToArray();
            Assert.Equal(1, files.Length);
        }
        private void WriteLogs(string logFilePath, int numLogs)
        {
            FileTraceWriter traceWriter = new FileTraceWriter(logFilePath, TraceLevel.Verbose);

            for (int i = 0; i < numLogs; i++)
            {
                traceWriter.Verbose(string.Format("Test message {0} {1}", Thread.CurrentThread.ManagedThreadId, i));
            }

            traceWriter.Flush();
        }
        public void Trace_WritesExpectedLogs()
        {
            DirectoryInfo directory = new DirectoryInfo(_logFilePath);
            directory.Create();

            int count = directory.EnumerateFiles().Count();
            Assert.Equal(0, count);

            FileTraceWriter traceWriter = new FileTraceWriter(_logFilePath, TraceLevel.Info);

            traceWriter.Verbose("Test Verbose");
            traceWriter.Info("Test Info");
            traceWriter.Warning("Test Warning");
            traceWriter.Error("Test Error");

            // trace a system event - expect it to be ignored
            var properties = new Dictionary<string, object>
            {
                { ScriptConstants.TracePropertyIsSystemTraceKey, true }
            };
            traceWriter.Info("Test System", properties);

            traceWriter.Flush();

            string logFile = directory.EnumerateFiles().First().FullName;
            string text = File.ReadAllText(logFile);
            Assert.True(text.Contains("Test Error"));
            Assert.True(text.Contains("Test Warning"));
            Assert.True(text.Contains("Test Info"));
            Assert.False(text.Contains("Test Verbose"));
            Assert.False(text.Contains("Test System"));
        }
        public void Trace_ReusesLastFile()
        {
            DirectoryInfo directory = new DirectoryInfo(_logFilePath);
            directory.Create();

            int count = directory.EnumerateFiles().Count();
            Assert.Equal(0, count);

            for (int i = 0; i < 3; i++)
            {
                FileTraceWriter traceWriter = new FileTraceWriter(_logFilePath, TraceLevel.Verbose);
                traceWriter.Verbose("Testing");
                traceWriter.Flush();
            }

            count = directory.EnumerateFiles().Count();
            Assert.Equal(1, count);

            string logFile = directory.EnumerateFiles().First().FullName;
            string[] fileLines = File.ReadAllLines(logFile);
            Assert.Equal(3, fileLines.Length);
        }