private void ParseSinks(Collection <LogSinkConfig> logSinks, string testAssemblyName) { // Build sinks and add them into the sinks collection. foreach (LogSinkConfig sink in logSinks) { bool sinkSupported = false; CustomLogSinkConfig customSink = sink as CustomLogSinkConfig; if (customSink != null) { sinkSupported = true; AddCustomSink( customSink.Name, customSink.Type, customSink.Identity); } FileLogSinkConfig fileSink = sink as FileLogSinkConfig; if (fileSink != null) { sinkSupported = true; AddFileSink( fileSink.Name, fileSink.Directory, CreateUniqueFileName(fileSink, testAssemblyName), fileSink.Format); } ConsoleLogSinkConfig consoleSink = sink as ConsoleLogSinkConfig; if (consoleSink != null) { sinkSupported = true; AddConsoleSink( consoleSink.ID); } if (!sinkSupported) { throw new InvalidOperationException("The specified sink type is not supported."); } } }
private static string CreateUniqueFileName(FileLogSinkConfig fileSink, string testAssemblyName) { string timeStampFormat = "{0:D4}-{1:D2}-{2:D2} {3:D2}_{4:D2}_{5:D2}_{6:D3}"; if (testAssemblyName == null) { throw new ArgumentNullException("Test Assembly Name"); } string uniqueName = string.Empty; string extension = string.Empty; if (0 == string.Compare("text", fileSink.Format, StringComparison.CurrentCultureIgnoreCase)) { extension = ".txt"; } else if (0 == string.Compare("xml", fileSink.Format, StringComparison.CurrentCultureIgnoreCase)) { extension = ".xml"; } else { throw new InvalidOperationException( string.Format("Unexpected file format for file sink {0}, the format for file sink can only be 'text' or 'xml'.", fileSink.Name)); } //use the time stamp to make the file name unique. DateTime timeStamp = DateTime.Now; string timeStampInfo = string.Format(timeStampFormat, timeStamp.Year, timeStamp.Month, timeStamp.Day, timeStamp.Hour, timeStamp.Minute, timeStamp.Second, timeStamp.Millisecond); if (string.IsNullOrEmpty(fileSink.File)) { uniqueName = "[" + testAssemblyName + "_" + fileSink.Name + "]" + timeStampInfo + extension; if (File.Exists(Path.Combine(fileSink.Directory, uniqueName))) { throw new InvalidOperationException( "File already exist: " + uniqueName); } } else { uniqueName = fileSink.File; if (File.Exists(Path.Combine(fileSink.Directory, uniqueName))) { uniqueName = "[" + testAssemblyName + "_" + fileSink.Name + "]" + timeStampInfo + " " + fileSink.File; if (File.Exists(Path.Combine(fileSink.Directory, uniqueName))) { throw new InvalidOperationException( "File already exist: " + uniqueName); } } } return(uniqueName); }
private static string CreateUniqueFileName(FileLogSinkConfig fileSink, string testAssemblyName) { string timeStampFormat = "{0:D4}-{1:D2}-{2:D2} {3:D2}_{4:D2}_{5:D2}_{6:D3}"; if (testAssemblyName == null) { throw new ArgumentNullException("Test Assembly Name"); } string uniqueName = string.Empty; string extension = string.Empty; if (0 == string.Compare("text", fileSink.Format, StringComparison.CurrentCultureIgnoreCase)) { extension = ".txt"; } else if (0 == string.Compare("xml", fileSink.Format, StringComparison.CurrentCultureIgnoreCase)) { extension = ".xml"; } else { throw new InvalidOperationException( string.Format("Unexpected file format for file sink {0}, the format for file sink can only be 'text' or 'xml'.", fileSink.Name)); } //use the time stamp to make the file name unique. DateTime timeStamp = DateTime.Now; string timeStampInfo = string.Format(timeStampFormat, timeStamp.Year, timeStamp.Month, timeStamp.Day, timeStamp.Hour, timeStamp.Minute, timeStamp.Second, timeStamp.Millisecond); if (string.IsNullOrEmpty(fileSink.File)) { uniqueName = "[" + testAssemblyName + "_" + fileSink.Name + "]" + timeStampInfo + extension; if (File.Exists(Path.Combine(fileSink.Directory, uniqueName))) { throw new InvalidOperationException( "File already exist: " + uniqueName); } } else { uniqueName = fileSink.File; if(File.Exists(Path.Combine(fileSink.Directory, uniqueName))) { uniqueName = "[" + testAssemblyName + "_" + fileSink.Name + "]" + timeStampInfo + " " + fileSink.File; if (File.Exists(Path.Combine(fileSink.Directory, uniqueName))) { throw new InvalidOperationException( "File already exist: " + uniqueName); } } } return uniqueName; }