/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/BinLogPathProvider.cs
55 строк
2 KB
David Barbet
Refactor LSP server logging to remove singleton lsp instance (#84001)
16 июн 2026, 05:04
Не верифицирован
16 июн 2026, 05:04
82e81e5
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Composition; using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.LanguageServer.Handler; using Microsoft.CodeAnalysis.Options; using Microsoft.Extensions.Logging; namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace; [ExportCSharpVisualBasicLspServiceFactory(typeof(BinLogPathProvider)), Shared] [method: ImportingConstructor] [method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] internal sealed class BinLogPathProviderFactory(IGlobalOptionService globalOptionService) : ILspServiceFactory { public ILspService CreateILspService(LspServices lspServices, WellKnownLspServerKinds serverKind) => new BinLogPathProvider(globalOptionService, lspServices.GetRequiredService<ILoggerFactory>()); } internal sealed class BinLogPathProvider : IBinLogPathProvider, ILspService { /// <summary> /// The suffix to use for the binary log name; incremented each time we have a new build. Should be incremented with <see cref="Interlocked.Increment(ref int)"/>. /// </summary> private int _binaryLogNumericSuffix; /// <summary> /// A GUID put into all binary log file names, so that way one session doesn't accidentally overwrite the logs from a prior session. /// </summary> private readonly Guid _binaryLogGuidSuffix = Guid.NewGuid(); private readonly IGlobalOptionService _globalOptionService; private readonly ILogger _logger; public BinLogPathProvider(IGlobalOptionService globalOptionService, ILoggerFactory loggerFactory) { _globalOptionService = globalOptionService; _logger = loggerFactory.CreateLogger<BinLogPathProvider>(); } public string? GetNewLogPath() { if (_globalOptionService.GetOption(LanguageServerProjectSystemOptionsStorage.BinaryLogPath) is not string binaryLogDirectory) return null; var numericSuffix = Interlocked.Increment(ref _binaryLogNumericSuffix); var binaryLogPath = Path.Combine(binaryLogDirectory, $"LanguageServerDesignTimeBuild-{_binaryLogGuidSuffix}-{numericSuffix}.binlog"); _logger.LogInformation($"Logging design-time builds to {binaryLogPath}"); return binaryLogPath; } }