Exemple #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"));
        }
Exemple #2
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 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"));
        }