Skip to content

Rework log builder to support logging to files #1066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ $script:RequiredBuildAssets = @{
'publish/OmniSharp.Extensions.LanguageServer.dll',
'publish/OmniSharp.Extensions.DebugAdapter.dll',
'publish/OmniSharp.Extensions.DebugAdapter.Server.dll',
'publish/MediatR.dll',
'publish/MediatR.Extensions.Microsoft.DependencyInjection.dll',
'publish/runtimes/linux-64/native/libdisablekeyecho.so',
'publish/runtimes/osx-64/native/libdisablekeyecho.dylib',
'publish/Serilog.dll',
Expand Down
1 change: 1 addition & 0 deletions src/PowerShellEditorServices/Hosting/EditorServicesHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ public void StartLogging(string logFilePath, PsesLogLevel logLevel)
{
Log.Logger = new LoggerConfiguration().Enrich.FromLogContext()
.WriteTo.File(logFilePath)
.MinimumLevel.Verbose()
.CreateLogger();
_factory = new LoggerFactory().AddSerilog(Log.Logger);
_logger = _factory.CreateLogger<EditorServicesHost>();
Expand Down
96 changes: 44 additions & 52 deletions src/PowerShellEditorServices/Server/PsesLanguageServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
using Microsoft.PowerShell.EditorServices.Handlers;
using Microsoft.PowerShell.EditorServices.Hosting;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
using OmniSharp.Extensions.LanguageServer.Server;
using Serilog;

namespace Microsoft.PowerShell.EditorServices.Server
{
Expand Down Expand Up @@ -59,59 +59,53 @@ public async Task StartAsync()
{
LanguageServer = await OmniSharp.Extensions.LanguageServer.Server.LanguageServer.From(options =>
{
options.AddDefaultLoggingProvider();
options.LoggerFactory = LoggerFactory;
ILogger logger = options.LoggerFactory.CreateLogger("OptionsStartup");
options.Services = new ServiceCollection()
.AddSingleton<WorkspaceService>()
.AddSingleton<SymbolsService>()
.AddSingleton<ConfigurationService>()
.AddSingleton<PowerShellContextService>(
(provider) =>
PowerShellContextService.Create(
LoggerFactory,
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
_profilePaths,
_featureFlags,
_enableConsoleRepl,
_internalHost,
_hostDetails,
_additionalModules))
.AddSingleton<TemplateService>()
.AddSingleton<EditorOperationsService>()
.AddSingleton<RemoteFileManagerService>()
.AddSingleton<ExtensionService>(
(provider) =>
{
var extensionService = new ExtensionService(
provider.GetService<PowerShellContextService>(),
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>());
extensionService.InitializeAsync(
serviceProvider: provider,
editorOperations: provider.GetService<EditorOperationsService>())
.Wait();
return extensionService;
})
.AddSingleton<AnalysisService>(
(provider) =>
{
return AnalysisService.Create(
provider.GetService<ConfigurationService>(),
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
options.LoggerFactory.CreateLogger<AnalysisService>());
});

(Stream input, Stream output) = GetInputOutputStreams();

options
.WithInput(input)
.WithOutput(output);

options.MinimumLogLevel = _minimumLogLevel;

logger.LogInformation("Adding handlers");

options
.WithOutput(output)
.WithServices(serviceCollection => serviceCollection
.AddSingleton<WorkspaceService>()
.AddSingleton<SymbolsService>()
.AddSingleton<ConfigurationService>()
.AddSingleton<PowerShellContextService>(
(provider) =>
PowerShellContextService.Create(
provider.GetService<ILoggerFactory>(),
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
_profilePaths,
_featureFlags,
_enableConsoleRepl,
_internalHost,
_hostDetails,
_additionalModules))
.AddSingleton<TemplateService>()
.AddSingleton<EditorOperationsService>()
.AddSingleton<RemoteFileManagerService>()
.AddSingleton<ExtensionService>(
(provider) =>
{
var extensionService = new ExtensionService(
provider.GetService<PowerShellContextService>(),
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>());
extensionService.InitializeAsync(
serviceProvider: provider,
editorOperations: provider.GetService<EditorOperationsService>())
.Wait();
return extensionService;
})
.AddSingleton<AnalysisService>(
(provider) =>
{
return AnalysisService.Create(
provider.GetService<ConfigurationService>(),
provider.GetService<OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(),
provider.GetService<ILoggerFactory>().CreateLogger<AnalysisService>());
}))
.ConfigureLogging(builder => builder
.AddSerilog(Log.Logger)
.SetMinimumLevel(LogLevel.Trace))
.AddDefaultLoggingProvider()
.WithHandler<WorkspaceSymbolsHandler>()
.WithHandler<TextDocumentHandler>()
.WithHandler<GetVersionHandler>()
Expand Down Expand Up @@ -154,8 +148,6 @@ await serviceProvider.GetService<PowerShellContextService>().SetWorkingDirectory
isPathAlreadyEscaped: false);
}
});

logger.LogInformation("Handlers added");
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
using OmniSharp.Extensions.DebugAdapter.Protocol.Events;
using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.JsonRpc;

namespace Microsoft.PowerShell.EditorServices.Handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Services;
using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.JsonRpc;

namespace Microsoft.PowerShell.EditorServices.Handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Services;
using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.JsonRpc;

namespace Microsoft.PowerShell.EditorServices.Handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.JsonRpc;

namespace Microsoft.PowerShell.EditorServices.Handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.JsonRpc;

namespace Microsoft.PowerShell.EditorServices.Handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.JsonRpc;

namespace Microsoft.PowerShell.EditorServices.Handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.JsonRpc;

namespace Microsoft.PowerShell.EditorServices.Handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.JsonRpc;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.JsonRpc;

namespace Microsoft.PowerShell.EditorServices.Handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;

namespace Microsoft.PowerShell.EditorServices.Handlers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Services;
using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.JsonRpc;

namespace Microsoft.PowerShell.EditorServices.Handlers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.Configuration;
using OmniSharp.Extensions.Embedded.MediatR;
using MediatR;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
Expand Down