private static async Task <LogHubLspLogger?> CreateLoggerAsync( VSShell.IAsyncServiceProvider?asyncServiceProvider, string serverTypeName, string?clientName, JsonRpc jsonRpc, CancellationToken cancellationToken) { if (asyncServiceProvider == null) { return(null); } var logName = $"Roslyn.{serverTypeName}.{clientName ?? "Default"}.{Interlocked.Increment(ref s_logHubSessionId)}"; var logId = new LogId(logName, new ServiceMoniker(typeof(LanguageServerTarget).FullName)); var serviceContainer = await VSShell.ServiceExtensions.GetServiceAsync <SVsBrokeredServiceContainer, IBrokeredServiceContainer>(asyncServiceProvider).ConfigureAwait(false); var service = serviceContainer.GetFullAccessServiceBroker(); var configuration = await TraceConfiguration.CreateTraceConfigurationInstanceAsync(service, cancellationToken).ConfigureAwait(false); var logOptions = new RpcContracts.Logging.LoggerOptions(new LoggingLevelSettings(SourceLevels.ActivityTracing | SourceLevels.Information)); var traceSource = await configuration.RegisterLogSourceAsync(logId, logOptions, cancellationToken).ConfigureAwait(false); // Associate this trace source with the jsonrpc conduit. This ensures that we can associate logs we report // with our callers and the operations they are performing. jsonRpc.ActivityTracingStrategy = new CorrelationManagerTracingStrategy { TraceSource = traceSource }; return(new LogHubLspLogger(configuration, traceSource)); }
public async Task <ILspLogger> CreateLoggerAsync(string serverTypeName, string?clientName, JsonRpc jsonRpc, CancellationToken cancellationToken) { var logName = $"Roslyn.{serverTypeName}.{clientName ?? "Default"}.{Interlocked.Increment(ref s_logHubSessionId)}"; var logId = new LogId(logName, new ServiceMoniker(typeof(LanguageServerTarget).FullName)); var serviceContainer = await _asyncServiceProvider.GetServiceAsync <SVsBrokeredServiceContainer, IBrokeredServiceContainer>(_threadingContext.JoinableTaskFactory).ConfigureAwait(false); var service = serviceContainer.GetFullAccessServiceBroker(); var configuration = await TraceConfiguration.CreateTraceConfigurationInstanceAsync(service, ownsServiceBroker : true, cancellationToken).ConfigureAwait(false); // Register the default log level as information. // Loghub will take care of cleaning up older logs from past sessions / current session // if it decides the log file sizes are too large. var loggingLevel = SourceLevels.ActivityTracing | SourceLevels.Information; var logOptions = new RpcContracts.Logging.LoggerOptions(new LoggingLevelSettings(loggingLevel)); var traceSource = await configuration.RegisterLogSourceAsync(logId, logOptions, cancellationToken).ConfigureAwait(false); // Associate this trace source with the jsonrpc conduit. This ensures that we can associate logs we report // with our callers and the operations they are performing. jsonRpc.ActivityTracingStrategy = new CorrelationManagerTracingStrategy { TraceSource = traceSource }; return(new LogHubLspLogger(configuration, traceSource)); }
public async Task <ILspLogger> CreateLoggerAsync(string serverTypeName, string?clientName, JsonRpc jsonRpc, CancellationToken cancellationToken) { var logName = $"Roslyn.{serverTypeName}.{clientName ?? "Default"}.{Interlocked.Increment(ref s_logHubSessionId)}"; var logId = new LogId(logName, new ServiceMoniker(typeof(LanguageServerTarget).FullName)); var serviceContainer = await VSShell.ServiceExtensions.GetServiceAsync <SVsBrokeredServiceContainer, IBrokeredServiceContainer>(_asyncServiceProvider).ConfigureAwait(false); var service = serviceContainer.GetFullAccessServiceBroker(); var configuration = await TraceConfiguration.CreateTraceConfigurationInstanceAsync(service, cancellationToken).ConfigureAwait(false); // Register the default log level as warning to avoid creating log files in the hundreds of GB. // This level can be overriden by setting the environment variable 'LogLevel' to the desired source level. // See https://dev.azure.com/devdiv/DevDiv/_git/VS?path=%2Fsrc%2FPlatform%2FUtilities%2FImpl%2FLogHub%2FLocalTraceHub.cs&version=GBmain&line=142&lineEnd=143&lineStartColumn=1&lineEndColumn=1&lineStyle=plain&_a=contents // This should be switched back to SourceLevels.Information once Loghub adds support for recyclying logs while VS is open. // See https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1359778/ var loggingLevel = SourceLevels.ActivityTracing | SourceLevels.Warning; // If VS was explicitly started with /log, then record all information logs as well. // This is extremely useful for development so that F5 deployment automatically logs everything. var wasVSStartedWithLogParameter = await _wasVSStartedWithLogParameterLazy.GetValueAsync(cancellationToken).ConfigureAwait(false); if (wasVSStartedWithLogParameter) { loggingLevel |= SourceLevels.Information; } var logOptions = new RpcContracts.Logging.LoggerOptions(new LoggingLevelSettings(loggingLevel)); var traceSource = await configuration.RegisterLogSourceAsync(logId, logOptions, cancellationToken).ConfigureAwait(false); // Associate this trace source with the jsonrpc conduit. This ensures that we can associate logs we report // with our callers and the operations they are performing. jsonRpc.ActivityTracingStrategy = new CorrelationManagerTracingStrategy { TraceSource = traceSource }; return(new LogHubLspLogger(configuration, traceSource)); }