public void RollingFlatFileTraceListenerReplacedEnviromentVariablesWillFallBackIfNotPrivilegesToRead() { string environmentVariable = "%USERPROFILE%"; string fileName = Path.Combine(environmentVariable, "foo.log"); EnvironmentPermission denyPermission = new EnvironmentPermission(PermissionState.Unrestricted); denyPermission.Deny(); try { RollingFlatFileTraceListener listener = new RollingFlatFileTraceListener(fileName, "header", "footer", null, 1, "", RollFileExistsBehavior.Increment, RollInterval.Day); 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 RollingFlatFileTraceListenerReplacedEnviromentVariables() { string fileName = @"%USERPROFILE%\foo.log"; string fileNameFromListener = string.Empty; RollingFlatFileTraceListener listener = new RollingFlatFileTraceListener(fileName, "header", "footer", null, 1, "", RollFileExistsBehavior.Increment, RollInterval.Day); listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test"); listener.Dispose(); string expandedFileName = Environment.ExpandEnvironmentVariables(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 static void CheckListener() { string environmentVariable = "%USERPROFILE%"; string fileName = Path.Combine(environmentVariable, "test.log"); RollingFlatFileTraceListener listener = new RollingFlatFileTraceListener(fileName, "header", "footer", null, 1, "", RollFileExistsBehavior.Increment, RollInterval.Day); listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test"); listener.Dispose(); }
void IDisposable.Dispose() { if (_rollingListener != null) { _rollingListener.Flush(); _rollingListener.Dispose(); if (_rollTrigger != null) { _rollTrigger.Dispose(); } } }
public void RollingFlatFileTraceListenerReplacedInexistingEnviromentVariables() { string fileName = @"tmp\%FOO%\%MY_VARIABLE%\foo.log"; RollingFlatFileTraceListener listener = new RollingFlatFileTraceListener(fileName, "header", "footer", null, 1, "", RollFileExistsBehavior.Increment, RollInterval.Day); listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test"); listener.Dispose(); string expandedFileName = EnvironmentHelper.ReplaceEnvironmentVariables(fileName); string expectedFileName = Path.GetFileName(expandedFileName); bool result = File.Exists(expandedFileName); Assert.IsTrue(result); File.Delete(expandedFileName); }
public void Dispose() { _rollingFlatFileTraceListener.Dispose(); }