Skip to content

Commit 86b153c

Browse files
TylerLeonhardtrjmholt
authored andcommitted
Rework log builder to support logging to files (#1066)
* Reword log builder * Change MediatR imports for new Omnisharp changes
1 parent 654540a commit 86b153c

17 files changed

+61
-66
lines changed

PowerShellEditorServices.build.ps1

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ $script:RequiredBuildAssets = @{
6666
'publish/OmniSharp.Extensions.LanguageServer.dll',
6767
'publish/OmniSharp.Extensions.DebugAdapter.dll',
6868
'publish/OmniSharp.Extensions.DebugAdapter.Server.dll',
69+
'publish/MediatR.dll',
70+
'publish/MediatR.Extensions.Microsoft.DependencyInjection.dll',
6971
'publish/runtimes/linux-64/native/libdisablekeyecho.so',
7072
'publish/runtimes/osx-64/native/libdisablekeyecho.dylib',
7173
'publish/Serilog.dll',

src/PowerShellEditorServices/Hosting/EditorServicesHost.cs

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public void StartLogging(string logFilePath, PsesLogLevel logLevel)
189189
{
190190
Log.Logger = new LoggerConfiguration().Enrich.FromLogContext()
191191
.WriteTo.File(logFilePath)
192+
.MinimumLevel.Verbose()
192193
.CreateLogger();
193194
_factory = new LoggerFactory().AddSerilog(Log.Logger);
194195
_logger = _factory.CreateLogger<EditorServicesHost>();

src/PowerShellEditorServices/Server/PsesLanguageServer.cs

+44-52
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
using Microsoft.PowerShell.EditorServices.Handlers;
1616
using Microsoft.PowerShell.EditorServices.Hosting;
1717
using Microsoft.PowerShell.EditorServices.Services;
18-
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
1918
using OmniSharp.Extensions.LanguageServer.Server;
19+
using Serilog;
2020

2121
namespace Microsoft.PowerShell.EditorServices.Server
2222
{
@@ -59,59 +59,53 @@ public async Task StartAsync()
5959
{
6060
LanguageServer = await OmniSharp.Extensions.LanguageServer.Server.LanguageServer.From(options =>
6161
{
62-
options.AddDefaultLoggingProvider();
63-
options.LoggerFactory = LoggerFactory;
64-
ILogger logger = options.LoggerFactory.CreateLogger("OptionsStartup");
65-
options.Services = new ServiceCollection()
66-
.AddSingleton<WorkspaceService>()
67-
.AddSingleton<SymbolsService>()
68-
.AddSingleton<ConfigurationService>()
69-
.AddSingleton<PowerShellContextService>(
70-
(provider) =>
71-
PowerShellContextService.Create(
72-
LoggerFactory,
73-
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
74-
_profilePaths,
75-
_featureFlags,
76-
_enableConsoleRepl,
77-
_internalHost,
78-
_hostDetails,
79-
_additionalModules))
80-
.AddSingleton<TemplateService>()
81-
.AddSingleton<EditorOperationsService>()
82-
.AddSingleton<RemoteFileManagerService>()
83-
.AddSingleton<ExtensionService>(
84-
(provider) =>
85-
{
86-
var extensionService = new ExtensionService(
87-
provider.GetService<PowerShellContextService>(),
88-
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>());
89-
extensionService.InitializeAsync(
90-
serviceProvider: provider,
91-
editorOperations: provider.GetService<EditorOperationsService>())
92-
.Wait();
93-
return extensionService;
94-
})
95-
.AddSingleton<AnalysisService>(
96-
(provider) =>
97-
{
98-
return AnalysisService.Create(
99-
provider.GetService<ConfigurationService>(),
100-
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
101-
options.LoggerFactory.CreateLogger<AnalysisService>());
102-
});
103-
10462
(Stream input, Stream output) = GetInputOutputStreams();
10563

10664
options
10765
.WithInput(input)
108-
.WithOutput(output);
109-
110-
options.MinimumLogLevel = _minimumLogLevel;
111-
112-
logger.LogInformation("Adding handlers");
113-
114-
options
66+
.WithOutput(output)
67+
.WithServices(serviceCollection => serviceCollection
68+
.AddSingleton<WorkspaceService>()
69+
.AddSingleton<SymbolsService>()
70+
.AddSingleton<ConfigurationService>()
71+
.AddSingleton<PowerShellContextService>(
72+
(provider) =>
73+
PowerShellContextService.Create(
74+
provider.GetService<ILoggerFactory>(),
75+
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
76+
_profilePaths,
77+
_featureFlags,
78+
_enableConsoleRepl,
79+
_internalHost,
80+
_hostDetails,
81+
_additionalModules))
82+
.AddSingleton<TemplateService>()
83+
.AddSingleton<EditorOperationsService>()
84+
.AddSingleton<RemoteFileManagerService>()
85+
.AddSingleton<ExtensionService>(
86+
(provider) =>
87+
{
88+
var extensionService = new ExtensionService(
89+
provider.GetService<PowerShellContextService>(),
90+
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>());
91+
extensionService.InitializeAsync(
92+
serviceProvider: provider,
93+
editorOperations: provider.GetService<EditorOperationsService>())
94+
.Wait();
95+
return extensionService;
96+
})
97+
.AddSingleton<AnalysisService>(
98+
(provider) =>
99+
{
100+
return AnalysisService.Create(
101+
provider.GetService<ConfigurationService>(),
102+
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
103+
provider.GetService<ILoggerFactory>().CreateLogger<AnalysisService>());
104+
}))
105+
.ConfigureLogging(builder => builder
106+
.AddSerilog(Log.Logger)
107+
.SetMinimumLevel(LogLevel.Trace))
108+
.AddDefaultLoggingProvider()
115109
.WithHandler<WorkspaceSymbolsHandler>()
116110
.WithHandler<TextDocumentHandler>()
117111
.WithHandler<GetVersionHandler>()
@@ -154,8 +148,6 @@ await serviceProvider.GetService<PowerShellContextService>().SetWorkingDirectory
154148
isPathAlreadyEscaped: false);
155149
}
156150
});
157-
158-
logger.LogInformation("Handlers added");
159151
});
160152
}
161153

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
using Microsoft.PowerShell.EditorServices.Services;
1414
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
1515
using OmniSharp.Extensions.DebugAdapter.Protocol.Events;
16-
using OmniSharp.Extensions.Embedded.MediatR;
16+
using MediatR;
1717
using OmniSharp.Extensions.JsonRpc;
1818

1919
namespace Microsoft.PowerShell.EditorServices.Handlers

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ExpandAliasHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using System.Threading.Tasks;
1010
using Microsoft.Extensions.Logging;
1111
using Microsoft.PowerShell.EditorServices.Services;
12-
using OmniSharp.Extensions.Embedded.MediatR;
12+
using MediatR;
1313
using OmniSharp.Extensions.JsonRpc;
1414

1515
namespace Microsoft.PowerShell.EditorServices.Handlers

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/GetCommandHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using System.Threading.Tasks;
1010
using Microsoft.Extensions.Logging;
1111
using Microsoft.PowerShell.EditorServices.Services;
12-
using OmniSharp.Extensions.Embedded.MediatR;
12+
using MediatR;
1313
using OmniSharp.Extensions.JsonRpc;
1414

1515
namespace Microsoft.PowerShell.EditorServices.Handlers

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IEvaluateHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6-
using OmniSharp.Extensions.Embedded.MediatR;
6+
using MediatR;
77
using OmniSharp.Extensions.JsonRpc;
88

99
namespace Microsoft.PowerShell.EditorServices.Handlers

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetCommentHelpHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6-
using OmniSharp.Extensions.Embedded.MediatR;
6+
using MediatR;
77
using OmniSharp.Extensions.JsonRpc;
88
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
99

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetPSHostProcessesHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6-
using OmniSharp.Extensions.Embedded.MediatR;
6+
using MediatR;
77
using OmniSharp.Extensions.JsonRpc;
88

99
namespace Microsoft.PowerShell.EditorServices.Handlers

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetRunspaceHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6-
using OmniSharp.Extensions.Embedded.MediatR;
6+
using MediatR;
77
using OmniSharp.Extensions.JsonRpc;
88

99
namespace Microsoft.PowerShell.EditorServices.Handlers

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IGetVersionHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55

66
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
7-
using OmniSharp.Extensions.Embedded.MediatR;
7+
using MediatR;
88
using OmniSharp.Extensions.JsonRpc;
99

1010
namespace Microsoft.PowerShell.EditorServices.Handlers

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/IInvokeExtensionCommandHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6-
using OmniSharp.Extensions.Embedded.MediatR;
6+
using MediatR;
77
using OmniSharp.Extensions.JsonRpc;
88
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
99

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ITemplateHandlers.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6-
using OmniSharp.Extensions.Embedded.MediatR;
6+
using MediatR;
77
using OmniSharp.Extensions.JsonRpc;
88

99
namespace Microsoft.PowerShell.EditorServices.Handlers

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/InvokeExtensionCommandHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Microsoft.Extensions.Logging;
99
using Microsoft.PowerShell.EditorServices.Services;
1010
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
11-
using OmniSharp.Extensions.Embedded.MediatR;
11+
using MediatR;
1212

1313
namespace Microsoft.PowerShell.EditorServices.Handlers
1414
{

src/PowerShellEditorServices/Services/PowerShellContext/Handlers/ShowHelpHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.Threading.Tasks;
99
using Microsoft.Extensions.Logging;
1010
using Microsoft.PowerShell.EditorServices.Services;
11-
using OmniSharp.Extensions.Embedded.MediatR;
11+
using MediatR;
1212
using OmniSharp.Extensions.JsonRpc;
1313

1414
namespace Microsoft.PowerShell.EditorServices.Handlers

src/PowerShellEditorServices/Services/TextDocument/Handlers/TextDocumentHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using Microsoft.Extensions.Logging;
1111
using Microsoft.PowerShell.EditorServices.Services;
1212
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
13-
using OmniSharp.Extensions.Embedded.MediatR;
13+
using MediatR;
1414
using OmniSharp.Extensions.LanguageServer.Protocol;
1515
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
1616
using OmniSharp.Extensions.LanguageServer.Protocol.Models;

src/PowerShellEditorServices/Services/Workspace/Handlers/ConfigurationHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using Microsoft.Extensions.Logging;
1111
using Microsoft.PowerShell.EditorServices.Services;
1212
using Microsoft.PowerShell.EditorServices.Services.Configuration;
13-
using OmniSharp.Extensions.Embedded.MediatR;
13+
using MediatR;
1414
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
1515
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
1616
using OmniSharp.Extensions.LanguageServer.Protocol.Server;

0 commit comments

Comments
 (0)