public void When_Tracing_Enabled_Custom_To_CustomTraceListener() { using var listener = new CustomTraceListener(); var options = new ClusterOptions(); options.WithThresholdTracing(new ThresholdOptions { Enabled = true, ThresholdListener = listener }); using var context = new ClusterContext(Mock.Of <ICluster>(), new CancellationTokenSource(), options); context.Start(); var tracer = context.ServiceProvider.GetRequiredService <IRequestTracer>(); var span = tracer.RequestSpan("works"); span.Dispose(); var activities = listener.GetActivities().Where(x => x.OperationName == "works").ToArray(); foreach (var activity in activities) { _output.WriteLine($"The name of the activity is '{activity.DisplayName}'"); } Assert.Single(activities); }
private static void Main() { try { Settings = new UserDefinedSettings(); } catch (CorruptedSettingsException ex) { string message = String.Format( "Cannot launch mrHelper because application configuration file at \"{0}\" could not be loaded. " + "It's probably corrupted. Try deleting the file or contact developers.", ex.ConfigFilePath); MessageBox.Show(message, "Fatal error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (LaunchContext context = new LaunchContext()) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += (sender, e) => HandleUnhandledException(e.Exception); try { initializeGitLabSharpLibrary(); string currentLogFileName = getLogFileName(context); CustomTraceListener listener = createTraceListener(currentLogFileName); if (listener == null) { // Cannot do anything good here return; } Directory.SetCurrentDirectory(Path.GetDirectoryName(context.CurrentProcess.MainModule.FileName)); ServiceManager = new ServiceManager(); createFeedbackReporter(currentLogFileName, listener); launchFromContext(context); } catch (Exception ex) // Any unhandled exception, including CSE { HandleUnhandledException(ex); } } }
private static CustomTraceListener createTraceListener(string currentLogFileName) { CustomTraceListener listener; try { listener = new CustomTraceListener(currentLogFileName, String.Format("Merge Request Helper {0} started. PID {1}", Application.ProductVersion, Process.GetCurrentProcess().Id)); Trace.Listeners.Add(listener); } catch (ArgumentException) { listener = null; } return(listener); }
public void When_Tracing_Disabled_Custom_To_CustomTraceListener() { using var listener = new CustomTraceListener(); var options = new ClusterOptions { TracingOptions = { Enabled = false } }; options.WithThresholdTracing(new ThresholdOptions { Enabled = false, ThresholdListener = listener }).WithOrphanTracing(options => options.Enabled = false); var services = options.BuildServiceProvider(); var noopRequestTracer = services.GetService(typeof(IRequestTracer)); Assert.IsAssignableFrom <NoopRequestTracer>(noopRequestTracer); }
void IContainerPolicyCreator.CreatePolicies( IPolicyList policyList, string instanceName, ConfigurationElement configurationObject, IConfigurationSource configurationSource) { BasicCustomTraceListenerData castConfigurationObject = (BasicCustomTraceListenerData)configurationObject; string listenerName = castConfigurationObject.Name; Type listenerType = castConfigurationObject.Type; string initData = castConfigurationObject.InitData; TraceOptions traceOutputOptions = castConfigurationObject.TraceOutputOptions; NameValueCollection attributes = castConfigurationObject.Attributes; TraceFilter filter = castConfigurationObject.Filter != SourceLevels.All ? new EventTypeFilter(castConfigurationObject.Filter) : null; string formatterName = castConfigurationObject is CustomTraceListenerData ? ((CustomTraceListenerData)castConfigurationObject).Formatter : null; policyList.Set <IBuildPlanPolicy>( new DelegateBuildPlanPolicy( context => { TraceListener traceListener = SystemDiagnosticsTraceListenerCreationHelper.CreateSystemDiagnosticsTraceListener( listenerName, listenerType, initData, attributes); traceListener.Name = listenerName; traceListener.TraceOutputOptions = traceOutputOptions; traceListener.Filter = filter; CustomTraceListener customTraceListener = traceListener as CustomTraceListener; if (customTraceListener != null && !string.IsNullOrEmpty(formatterName)) { IBuilderContext formatterContext = context.CloneForNewBuild(NamedTypeBuildKey.Make <ILogFormatter>(formatterName), null); customTraceListener.Formatter = (ILogFormatter)formatterContext.Strategies.ExecuteBuildUp(formatterContext); } return(traceListener); }), new NamedTypeBuildKey(listenerType, instanceName)); }
private static void createFeedbackReporter(string currentLogFileName, CustomTraceListener listener) { FeedbackReporter = new FeedbackReporter( () => { listener.Flush(); listener.Close(); Trace.Listeners.Remove(listener); }, () => { try { listener = new CustomTraceListener(currentLogFileName, null); Trace.Listeners.Add(listener); } catch (ArgumentException) { // Cannot do anything good here } }, getApplicationDataPath()); }
public void When_Tracing_Enabled_Custom_To_CustomTraceListener_Not_Disposed() { using var listener = new CustomTraceListener(); var options = new ClusterOptions(); options.WithThresholdTracing(new ThresholdOptions { Enabled = true, ThresholdListener = listener }); using (var context = new ClusterContext(Mock.Of <ICluster>(), new CancellationTokenSource(), options)) { context.Start(); var tracer = context.ServiceProvider.GetRequiredService <IRequestTracer>(); var span = tracer.RequestSpan("works"); span.Dispose(); } Assert.False(listener.Disposed); }
public void Setup() { this.listener = new CustomTraceListener(); Trace.Listeners.Add(listener); }
private static void Main() { using (LaunchContext context = new LaunchContext()) { Application.ThreadException += (sender, e) => HandleUnhandledException(e.Exception); try { string currentLogFileName = getLogFileName(context); CustomTraceListener listener = null; try { listener = new CustomTraceListener(currentLogFileName, String.Format("Merge Request Helper {0} started. PID {1}", Application.ProductVersion, Process.GetCurrentProcess().Id)); Trace.Listeners.Add(listener); } catch (ArgumentException) { // Cannot do anything good here return; } Directory.SetCurrentDirectory(Path.GetDirectoryName(context.CurrentProcess.MainModule.FileName)); ServiceManager = new ServiceManager(); FeedbackReporter = new FeedbackReporter( () => { listener.Flush(); listener.Close(); Trace.Listeners.Remove(listener); }, () => { try { listener = new CustomTraceListener(currentLogFileName, null); Trace.Listeners.Add(listener); } catch (Exception) { // Cannot do anything good here } }, getApplicationDataPath()); LaunchOptions options = LaunchOptions.FromContext(context); switch (options.Mode) { case LaunchOptions.LaunchMode.DiffTool: onLaunchFromDiffTool(options); break; case LaunchOptions.LaunchMode.Register: if (registerCustomProtocol()) { integrateInGitUI(); } break; case LaunchOptions.LaunchMode.Unregister: unregisterCustomProtocol(); break; case LaunchOptions.LaunchMode.Normal: if (context.IsRunningSingleInstance) { onLaunchMainInstace(options); } else { onLaunchAnotherInstance(options, context); } break; default: Debug.Assert(false); break; } } catch (Exception ex) // whatever unhandled exception { HandleUnhandledException(ex); } } }