public void Cleanup() { // Restoring to initial state for EqtTrace EqtTrace.InitializeTrace(traceFileName, PlatformTraceLevel.Verbose); #if NET451 EqtTrace.TraceLevel = traceLevel; #else EqtTrace.TraceLevel = (PlatformTraceLevel)traceLevel; #endif }
/// <summary> /// Initialize diag logging. /// </summary> /// <param name="diagFilePath">Diag file path.</param> /// <param name="diagParameters">Diag parameters</param> private void InitializeDiagLogging(string diagFilePath, Dictionary <string, string> diagParameters) { // Get trace level from diag parameters. var traceLevel = GetDiagTraceLevel(diagParameters); // Initialize trace. // Trace initialized is false in case of any exception at time of initialization like Catch exception(UnauthorizedAccessException, PathTooLongException...) var traceInitialized = EqtTrace.InitializeTrace(diagFilePath, traceLevel); // Show console warning in case trace is not initialized. if (!traceInitialized && !string.IsNullOrEmpty(EqtTrace.ErrorOnInitialization)) { ConsoleOutput.Instance.Warning(false, EqtTrace.ErrorOnInitialization); } }
public static void Init(TestContext testContext) { // Set DoNotInitailize to false. EqtTrace.DoNotInitailize = false; dirPath = Path.Combine(Path.GetTempPath(), "TraceUT"); try { Directory.CreateDirectory(dirPath); logFile = Path.Combine(dirPath, "trace.log"); } catch (Exception ex) { Console.WriteLine(ex.Message); } EqtTrace.InitializeTrace(logFile, PlatformTraceLevel.Off); }
private static void InitializeEqtTrace(IDictionary <string, string> argsDictionary) { // Setup logging if enabled if (argsDictionary.TryGetValue(LogFileArgument, out var logFile)) { var traceLevelInt = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, TraceLevelArgument); // In case traceLevelInt is not defined in PlatfromTraceLevel, default it to verbose. var traceLevel = Enum.IsDefined(typeof(PlatformTraceLevel), traceLevelInt) ? (PlatformTraceLevel)traceLevelInt : PlatformTraceLevel.Verbose; EqtTrace.InitializeTrace(logFile, traceLevel); } else { EqtTrace.DoNotInitailize = true; } }
public void SetupChannelShouldCreateTimestampedLogFileForHost() { this.mockRequestSender.Setup(rs => rs.InitializeCommunication()).Returns(123); EqtTrace.InitializeTrace("log.txt", PlatformTraceLevel.Verbose); this.testOperationManager.SetupChannel(Enumerable.Empty <string>(), this.defaultRunSettings); this.mockTestHostManager.Verify( th => th.GetTestHostProcessStartInfo( It.IsAny <IEnumerable <string> >(), It.IsAny <Dictionary <string, string> >(), It.Is <TestRunnerConnectionInfo>( t => t.LogFile.Contains("log.host." + DateTime.Now.ToString("yy-MM-dd")) && t.LogFile.Contains("_" + Thread.CurrentThread.ManagedThreadId + ".txt")))); #if NET451 EqtTrace.TraceLevel = TraceLevel.Off; #else EqtTrace.TraceLevel = PlatformTraceLevel.Off; #endif }
public void InitializeShouldPassDiagArgumentsIfDiagIsEnabled() { // Saving the EqtTrace state #if NET451 var traceLevel = EqtTrace.TraceLevel; EqtTrace.TraceLevel = TraceLevel.Off; #else var traceLevel = (TraceLevel)EqtTrace.TraceLevel; EqtTrace.TraceLevel = (PlatformTraceLevel)TraceLevel.Off; #endif var traceFileName = EqtTrace.LogFile; try { EqtTrace.InitializeTrace("mylog.txt", PlatformTraceLevel.Info); this.mockDataCollectionRequestSender.Setup(x => x.WaitForRequestHandlerConnection(It.IsAny <int>())).Returns(true); this.proxyDataCollectionManager.Initialize(); var expectedTraceLevel = (int)PlatformTraceLevel.Info; this.mockDataCollectionLauncher.Verify( x => x.LaunchDataCollector( It.IsAny <IDictionary <string, string> >(), It.Is <IList <string> >(list => list.Contains("--diag") && list.Contains("--tracelevel") && list.Contains(expectedTraceLevel.ToString()))), Times.Once); } finally { // Restoring to initial state for EqtTrace EqtTrace.InitializeTrace(traceFileName, PlatformTraceLevel.Verbose); #if NET451 EqtTrace.TraceLevel = traceLevel; #else EqtTrace.TraceLevel = (PlatformTraceLevel)traceLevel; #endif } }
public void Run(string[] args) { WaitForDebuggerIfEnabled(); var argsDictionary = CommandLineArgumentsHelper.GetArgumentsDictionary(args); // Setup logging if enabled string logFile; if (argsDictionary.TryGetValue(LogFileArgument, out logFile)) { var traceLevelInt = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, TraceLevelArgument); var isTraceLevelArgValid = Enum.IsDefined(typeof(PlatformTraceLevel), traceLevelInt); // In case traceLevelInt is not defined in PlatfromTraceLevel, default it to verbose. var traceLevel = isTraceLevelArgValid ? (PlatformTraceLevel)traceLevelInt : PlatformTraceLevel.Verbose; // Initialize trace. EqtTrace.InitializeTrace(logFile, traceLevel); // Log warning in case tracelevel passed in arg is invalid if (!isTraceLevelArgValid) { EqtTrace.Warning("DataCollectorMain.Run: Invalid trace level: {0}, defaulting to verbose tracelevel.", traceLevelInt); } } else { EqtTrace.DoNotInitailize = true; } if (EqtTrace.IsVerboseEnabled) { var version = typeof(DataCollectorMain) .GetTypeInfo() .Assembly .GetCustomAttribute <AssemblyInformationalVersionAttribute>()?.InformationalVersion; EqtTrace.Verbose($"Version: { version }"); } SetCultureSpecifiedByUser(); EqtTrace.Info("DataCollectorMain.Run: Starting data collector run with args: {0}", string.Join(",", args)); // Attach to exit of parent process var parentProcessId = CommandLineArgumentsHelper.GetIntArgFromDict(argsDictionary, ParentProcessArgument); EqtTrace.Info("DataCollector: Monitoring parent process with id: '{0}'", parentProcessId); this.processHelper.SetExitCallback( parentProcessId, (obj) => { EqtTrace.Info("DataCollector: ParentProcess '{0}' Exited.", parentProcessId); this.environment.Exit(1); }); // Get server port and initialize communication. string portValue; int port = argsDictionary.TryGetValue(PortArgument, out portValue) ? int.Parse(portValue) : 0; if (port <= 0) { throw new ArgumentException("Incorrect/No Port number"); } this.requestHandler.InitializeCommunication(port); // Can only do this after InitializeCommunication because datacollector cannot "Send Log" unless communications are initialized if (!string.IsNullOrEmpty(EqtTrace.LogFile)) { (this.requestHandler as DataCollectionRequestHandler)?.SendDataCollectionMessage(new DataCollectionMessageEventArgs(TestMessageLevel.Informational, string.Format("Logging DataCollector Diagnostics in file: {0}", EqtTrace.LogFile))); } // Start processing async in a different task EqtTrace.Info("DataCollector: Start Request Processing."); StartProcessing(); }