public void ReadWithArguments() { // Arrange string logCfgFn = Path.Combine(TestContext.CurrentContext.TestDirectory, "_utlog3.cfg"); // Act LogConfiguration lgCfg = ConfigurationReader.ReadFile(logCfgFn, false); // Assert Assert.IsNotNull(lgCfg); Assert.AreEqual(ELogLevel.Debug, lgCfg.Level); Assert.AreEqual("%date(dd.MM.yyyy HH:mm:ss:fff) %level %text%nl", lgCfg.Pattern); Assert.AreEqual(3, lgCfg.Streams.Length); ILogStream debugStream = lgCfg.Streams[0]; Assert.AreEqual(typeof(DebugStream), debugStream.GetType()); ILogStream consoleStream = lgCfg.Streams[1]; Assert.AreEqual(typeof(ConsoleStream), consoleStream.GetType()); ILogStream fileStream = lgCfg.Streams[2]; Assert.AreEqual(typeof(FileStream), fileStream.GetType()); }
public void ReadFileWithFlags() { // Arrange string logCfgFn = Path.Combine(TestContext.CurrentContext.TestDirectory, "_utlog2.cfg"); // Act LogConfiguration lgCfg = ConfigurationReader.ReadFile(logCfgFn, false); // Assert Assert.IsNotNull(lgCfg); Assert.AreEqual(ELogLevel.Debug, lgCfg.Level); Assert.AreEqual("%date %level %text%nl", lgCfg.Pattern); Assert.AreEqual(2, lgCfg.Streams.Length); ILogStream consoleStream = lgCfg.Streams[0]; Assert.AreEqual(typeof(ConsoleStream), consoleStream.GetType()); ILogStream fileStream = lgCfg.Streams[1]; Assert.AreEqual(typeof(FileStream), fileStream.GetType()); Assert.AreEqual("_lfc2.txt", ((FileStream)fileStream).FileName); Assert.AreEqual(true, ((FileStream)fileStream).Append); Assert.AreEqual(ELockingModel.Minimal, ((FileStream)fileStream).LockingModel); }
/// <summary> /// Sets the <paramref name="property"/> of the given <paramref name="logStream"/> /// to the specified <paramref name="value"/>. If the <paramref name="logStream"/> does /// not own the declared <paramref name="property"/>, nothing will happen. /// </summary> private static void SetStreamProperty(ILogStream logStream, string property, string value) { if (logStream == null) { return; } string lcProp = property.ToLower(); PropertyInfo[] logStreamProperties = logStream.GetType().GetProperties(); for (int i = -1; ++i != logStreamProperties.Length;) { PropertyInfo logStreamProperty = logStreamProperties[i]; string lcStreamProp = logStreamProperty.Name.ToLower(); if (lcStreamProp != lcProp) { continue; } object val; Type propertyType = logStreamProperty.PropertyType; if (propertyType.IsEnum) { val = Enum.Parse(propertyType, value, true); } else if (propertyType.IsArray && propertyType.GetElementType() == typeof(string)) { string[] types = value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int j = -1, jlen = types.Length; ++j != jlen;) { types[j] = types[j].Trim(); } val = types; } else { val = Convert.ChangeType(value, propertyType); } logStreamProperty.SetValue(logStream, val); return; } }
public void ReadWithCustomStream() { // Arrange string logCfgFn = Path.Combine(TestContext.CurrentContext.TestDirectory, "_utlog4.cfg"); // Act LogConfiguration lgCfg = ConfigurationReader.ReadFile(logCfgFn, false); // Assert Assert.IsNotNull(lgCfg); Assert.AreEqual(ELogLevel.Debug, lgCfg.Level); Assert.AreEqual("%date %level %text%nl", lgCfg.Pattern); Assert.AreEqual(2, lgCfg.Streams.Length); ILogStream customStream = lgCfg.Streams[0]; Assert.AreEqual(typeof(ConsoleStream), customStream.GetType()); ILogStream hiddenStream = lgCfg.Streams[1]; Assert.AreEqual(typeof(HiddenStream), hiddenStream.GetType()); }