public void FlatFileListenerReplacedEnviromentVariablesWillFallBackIfNotPrivilegesToRead()
        {
            string environmentVariable = "%USERPROFILE%";
            string fileName            = Path.Combine(environmentVariable, "foo.log");

            EnvironmentPermission denyPermission = new EnvironmentPermission(PermissionState.Unrestricted);

            denyPermission.Deny();

            try
            {
                FlatFileTraceListener listener = new FlatFileTraceListener(fileName);
                listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test");
                listener.Dispose();
            }
            catch (InvalidOperationException)
            {
                throw;
            }
            finally
            {
                EnvironmentPermission.RevertAll();
            }

            Assert.Fail("Permission was not denied.");
        }
        public void FlatFileListenerReplacedEnviromentVariables()
        {
            string fileName = @"%USERPROFILE%\foo.log";

            string fileNameFromListener = string.Empty;

            FlatFileTraceListener listener = new FlatFileTraceListener(fileName);

            listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test");
            listener.Dispose();

            string expandedFileName = EnvironmentHelper.ReplaceEnvironmentVariables(fileName);

            bool result = File.Exists(expandedFileName);

            Assert.IsTrue(result);

            using (FileStream stream = File.Open(expandedFileName, FileMode.Open))
            {
                fileNameFromListener = stream.Name;
            }

            File.Delete(expandedFileName);

            Assert.AreEqual(expandedFileName, fileNameFromListener);
        }
Ejemplo n.º 3
0
        public static void CheckListener()
        {
            string environmentVariable = "%USERPROFILE%";
            string fileName = Path.Combine(environmentVariable, "test.log");

            FlatFileTraceListener listener = new FlatFileTraceListener(fileName);
            listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test");
            listener.Dispose();
        }
        public void MessageIsWrittenWhenUsingJsonFormatterWithFlatFileTraceListener()
        {
            this.fileNameWithoutExtension = Guid.NewGuid().ToString();
            this.fileName = this.fileNameWithoutExtension + JsonLogFormatterFixture.Extension;

            using (FlatFileTraceListener tracelistener = new FlatFileTraceListener(this.fileName, null, null, new JsonLogFormatter(JsonFormatting.Indented)))
            {
                tracelistener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test");
                tracelistener.Dispose();
                Assert.IsTrue(File.Exists(this.fileName));

                string strLog = LogFileReader.ReadFileWithoutLock(this.fileName);
                StringAssert.Contains(strLog, "source Error: 1 : This is a test\r\n");
            }
        }
Ejemplo n.º 5
0
        public void FlatFileListenerReplacedInexistingEnviromentVariables()
        {
            string fileName = @"a\%FOO%\%MY_VARIABLE%\foo.log";

            FlatFileTraceListener listener = new FlatFileTraceListener(fileName);

            listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test");
            listener.Dispose();

            string fileNameFromListener = string.Empty;
            string expandedFileName     = EnvironmentHelper.ReplaceEnvironmentVariables(fileName);
            string expectedFileName     = Path.GetFileName(expandedFileName);

            bool result = File.Exists(expandedFileName);

            Assert.IsTrue(result);

            File.Delete(expandedFileName);
        }
        public void FlatFileListenerReplacedEnviromentVariablesWillFallBackIfNotPrivilegesToRead()
        {
            string environmentVariable = "%USERPROFILE%";
            string fileName = Path.Combine(environmentVariable, "foo.log");

            EnvironmentPermission denyPermission = new EnvironmentPermission(PermissionState.Unrestricted);
            denyPermission.Deny();

            try
            {
                FlatFileTraceListener listener = new FlatFileTraceListener(fileName);
                listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test");
                listener.Dispose();
            }
            finally
            {
                EnvironmentPermission.RevertAll();
            }

            Assert.Fail("Permission was not denied.");
        }
        public static void CheckListener()
        {
            string environmentVariable = "%USERPROFILE%";
            string fileName = Path.Combine(environmentVariable, "test.log");

            FlatFileTraceListener listener = new FlatFileTraceListener(fileName);
            listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test");
            listener.Dispose();
        }
        public void FlatFileListenerReplacedEnviromentVariables()
        {
            string fileName = @"%USERPROFILE%\foo.log";

            string fileNameFromListener = string.Empty;

            FlatFileTraceListener listener = new FlatFileTraceListener(fileName);

            listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test");
            listener.Dispose();

            string expandedFileName = EnvironmentHelper.ReplaceEnvironmentVariables(fileName);

            bool result = File.Exists(expandedFileName);

            Assert.IsTrue(result);

            using (FileStream stream = File.Open(expandedFileName, FileMode.Open))
            {
                fileNameFromListener = stream.Name;
            }

            File.Delete(expandedFileName);

            Assert.AreEqual(expandedFileName, fileNameFromListener);
        }
        public void FlatFileListenerReplacedInexistingEnviromentVariables()
        {
            string fileName = @"%FOO%\%MY_VARIABLE%\foo.log";

            FlatFileTraceListener listener = new FlatFileTraceListener(fileName);

            listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test");
            listener.Dispose();

            string fileNameFromListener = string.Empty;
            string expandedFileName = EnvironmentHelper.ReplaceEnvironmentVariables(fileName);
            string expectedFileName = Path.GetFileName(expandedFileName);

            bool result = File.Exists(expandedFileName);

            Assert.IsTrue(result);

            File.Delete(expandedFileName);

            Assert.AreEqual(expectedFileName, expandedFileName);
        }