Skip to content

Commit 8a1e9bd

Browse files
authored
Change logging to use Serilog (#666)
* Introduce serilog as logger backend * Put netstandard first in csproj files * Add serilog logic, begin internal builder for logger * Add log builder, switch log use, add comments * Add Serilog DLL to module output * Update Third Party Notices * Make file logging asynchronous * Add static null logger * Use cross-platform newlines
1 parent 7116445 commit 8a1e9bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+523
-368
lines changed

PowerShellEditorServices.build.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ task TestServer -If { !$script:IsUnix } {
177177
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild }
178178
}
179179

180-
task TestProtocol -If { !$script:IsUnix} {
180+
task TestProtocol -If { !$script:IsUnix } {
181181
Set-Location .\test\PowerShellEditorServices.Test.Protocol\
182182
exec { & $script:dotnetExe build -c $Configuration -f net452 }
183183
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild }
184184
}
185185

186-
task TestHost -If { !$script:IsUnix} {
186+
task TestHost -If { !$script:IsUnix } {
187187
Set-Location .\test\PowerShellEditorServices.Test.Host\
188188
exec { & $script:dotnetExe build -c $Configuration -f net452 }
189189
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild }
@@ -204,10 +204,14 @@ task LayoutModule -After Build {
204204
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop -Type Directory | Out-Null
205205
New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\Core -Type Directory | Out-Null
206206

207+
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices\bin\$Configuration\netstandard1.6\publish\Serilog*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\
208+
207209
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\netstandard1.6\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\
208210
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\netstandard1.6\UnixConsoleEcho.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\
209211
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\netstandard1.6\libdisablekeyecho.* -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\
210212
if (!$script:IsUnix) {
213+
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices\bin\$Configuration\net451\Serilog*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop
214+
211215
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\
212216
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\Newtonsoft.Json.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\
213217
Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\UnixConsoleEcho.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\

Third Party Notices.txt

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This file is based on or incorporates material from the projects listed below (T
55
UnixConsoleEcho
66

77
Copyright (c) 2017 Patrick Meinecke
8-
Provided for Informational Purposes Only
8+
Provided for Informational Purposes Only
99

1010
MIT License
1111

@@ -14,3 +14,75 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
1414
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1515

1616
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17+
18+
---
19+
20+
Serilog
21+
22+
Copyright 2013-2015 Serilog Contributors
23+
24+
Licensed under the Apache License, Version 2.0 (the "License");
25+
you may not use this file except in compliance with the License.
26+
You may obtain a copy of the License at
27+
28+
http://www.apache.org/licenses/LICENSE-2.0
29+
30+
Unless required by applicable law or agreed to in writing, software
31+
distributed under the License is distributed on an "AS IS" BASIS,
32+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33+
See the License for the specific language governing permissions and
34+
limitations under the License.
35+
36+
---
37+
38+
Serilog.Sinks.Async
39+
40+
Copyright 2013-2015 Serilog Contributors
41+
42+
Licensed under the Apache License, Version 2.0 (the "License");
43+
you may not use this file except in compliance with the License.
44+
You may obtain a copy of the License at
45+
46+
http://www.apache.org/licenses/LICENSE-2.0
47+
48+
Unless required by applicable law or agreed to in writing, software
49+
distributed under the License is distributed on an "AS IS" BASIS,
50+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
51+
See the License for the specific language governing permissions and
52+
limitations under the License.
53+
54+
---
55+
56+
Serilog.Sinks.File
57+
58+
Copyright 2013-2015 Serilog Contributors
59+
60+
Licensed under the Apache License, Version 2.0 (the "License");
61+
you may not use this file except in compliance with the License.
62+
You may obtain a copy of the License at
63+
64+
http://www.apache.org/licenses/LICENSE-2.0
65+
66+
Unless required by applicable law or agreed to in writing, software
67+
distributed under the License is distributed on an "AS IS" BASIS,
68+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
69+
See the License for the specific language governing permissions and
70+
limitations under the License.
71+
72+
---
73+
74+
Serilog.Sinks.Console
75+
76+
Copyright 2013-2015 Serilog Contributors
77+
78+
Licensed under the Apache License, Version 2.0 (the "License");
79+
you may not use this file except in compliance with the License.
80+
You may obtain a copy of the License at
81+
82+
http://www.apache.org/licenses/LICENSE-2.0
83+
84+
Unless required by applicable law or agreed to in writing, software
85+
distributed under the License is distributed on an "AS IS" BASIS,
86+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
87+
See the License for the specific language governing permissions and
88+
limitations under the License.

src/PowerShellEditorServices.Host/CodeLens/CodeLensFeature.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,4 @@ private class CodeLensData
160160
public string ProviderId {get; set; }
161161
}
162162
}
163-
}
163+
}

src/PowerShellEditorServices.Host/EditorServicesHost.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ public EditorServicesHost(
140140
/// <param name="logLevel">The minimum level of log messages to be written.</param>
141141
public void StartLogging(string logFilePath, LogLevel logLevel)
142142
{
143-
this.logger = new FileLogger(logFilePath, logLevel);
143+
this.logger = Logging.CreateLogger()
144+
.LogLevel(logLevel)
145+
.AddLogFile(logFilePath)
146+
.Build();
144147

145148
#if CoreCLR
146149
FileVersionInfo fileVersionInfo =

src/PowerShellEditorServices.Host/PowerShellEditorServices.Host.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PropertyGroup>
55
<AssemblyTitle>PowerShell Editor Services Host Process</AssemblyTitle>
66
<Description>Provides a process for hosting the PowerShell Editor Services library exposed by a JSON message protocol.</Description>
7-
<TargetFrameworks>net451;netstandard1.6</TargetFrameworks>
7+
<TargetFrameworks>netstandard1.6;net451</TargetFrameworks>
88
<AssemblyName>Microsoft.PowerShell.EditorServices.Host</AssemblyName>
99
</PropertyGroup>
1010

src/PowerShellEditorServices.Protocol/MessageProtocol/Channel/TcpSocketClientChannel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ public static async Task<TcpSocketClientChannel> Connect(
6161
return clientChannel;
6262
}
6363
}
64-
}
64+
}

src/PowerShellEditorServices.Protocol/MessageProtocol/Channel/TcpSocketServerChannel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ protected override void Shutdown()
5555
}
5656
}
5757
}
58-
}
58+
}

src/PowerShellEditorServices.Protocol/PowerShellEditorServices.Protocol.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PropertyGroup>
55
<AssemblyTitle>PowerShell Editor Services Host Protocol Library</AssemblyTitle>
66
<Description>Provides message types and client/server APIs for the PowerShell Editor Services JSON protocol.</Description>
7-
<TargetFrameworks>net451;netstandard1.6</TargetFrameworks>
7+
<TargetFrameworks>netstandard1.6;net451;</TargetFrameworks>
88
<AssemblyName>Microsoft.PowerShell.EditorServices.Protocol</AssemblyName>
99
</PropertyGroup>
1010

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public DebugAdapter(
5555
}
5656

5757
/// <summary>
58-
/// Gets a boolean that indicates whether the current debug adapter is
58+
/// Gets a boolean that indicates whether the current debug adapter is
5959
/// using a temporary integrated console.
6060
/// </summary>
6161
public bool IsUsingTempIntegratedConsole { get; private set; }
@@ -506,7 +506,7 @@ protected async Task HandleSetBreakpointsRequest(
506506
}
507507
}
508508
catch (Exception e) when (
509-
e is FileNotFoundException ||
509+
e is FileNotFoundException ||
510510
e is DirectoryNotFoundException ||
511511
e is IOException ||
512512
e is NotSupportedException ||
@@ -653,7 +653,7 @@ protected async Task HandleSetExceptionBreakpointsRequest(
653653
RequestContext<object> requestContext)
654654
{
655655
// TODO: When support for exception breakpoints (unhandled and/or first chance)
656-
// are added to the PowerShell engine, wire up the VSCode exception
656+
// are added to the PowerShell engine, wire up the VSCode exception
657657
// breakpoints here using the pattern below to prevent bug regressions.
658658
//if (!this.noDebug)
659659
//{

src/PowerShellEditorServices.Protocol/Server/LanguageServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public IEditorOperations EditorOperations
5454
/// <param name="messageHandlers">An object that manages all of the message handlers</param>
5555
/// <param name="messageSender">The message sender</param>
5656
/// <param name="serverCompletedTask">A TaskCompletionSource<bool> that will be completed to stop the running process</param>
57-
/// <param name="logger">The logger</param>
57+
/// <param name="logger">The logger.</param>
5858
public LanguageServer(
5959
EditorSession editorSession,
6060
IMessageHandlers messageHandlers,

src/PowerShellEditorServices.Protocol/Server/LanguageServerSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void Update(
9595
logger.Write(LogLevel.Verbose, $"Using Script Analyzer settings path - '{settingsPath ?? ""}'.");
9696
}
9797
catch (Exception ex) when (
98-
ex is NotSupportedException ||
98+
ex is NotSupportedException ||
9999
ex is PathTooLongException ||
100100
ex is SecurityException)
101101
{

src/PowerShellEditorServices.VSCode/PowerShellEditorServices.VSCode.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PropertyGroup>
55
<AssemblyTitle>PowerShell Editor Services, Visual Studio Code Extensions</AssemblyTitle>
66
<Description>Provides added functionality to PowerShell Editor Services for the Visual Studio Code editor.</Description>
7-
<TargetFrameworks>net451;netstandard1.6</TargetFrameworks>
7+
<TargetFrameworks>netstandard1.6;net451</TargetFrameworks>
88
<AssemblyName>Microsoft.PowerShell.EditorServices.VSCode</AssemblyName>
99
</PropertyGroup>
1010

src/PowerShellEditorServices/Components/FeatureComponentBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ public abstract class FeatureComponentBase<TProvider>
3434

3535
/// <summary>
3636
/// Creates an instance of the FeatureComponentBase class with
37-
/// the specified ILoggger.
37+
/// the specified ILogger.
3838
/// </summary>
39-
/// <param name="logger">The ILogger to use for this instance.</param>
39+
/// <param name="logger">The ILogger implementation to use for this instance.</param>
4040
public FeatureComponentBase(ILogger logger)
4141
{
4242
this.Providers = new FeatureProviderCollection<TProvider>();

src/PowerShellEditorServices/Console/ChoicePromptHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public abstract class ChoicePromptHandler : PromptHandler
4949
#endregion
5050

5151
/// <summary>
52-
///
52+
///
5353
/// </summary>
5454
/// <param name="logger">An ILogger implementation used for writing log messages.</param>
5555
public ChoicePromptHandler(ILogger logger) : base(logger)

src/PowerShellEditorServices/Console/InputPromptHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public abstract class InputPromptHandler : PromptHandler
3333
#endregion
3434

3535
/// <summary>
36-
///
36+
///
3737
/// </summary>
3838
/// <param name="logger">An ILogger implementation used for writing log messages.</param>
3939
public InputPromptHandler(ILogger logger) : base(logger)

src/PowerShellEditorServices/Console/PromptHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ namespace Microsoft.PowerShell.EditorServices.Console
1414
public abstract class PromptHandler
1515
{
1616
/// <summary>
17-
/// Gets the ILogger used for this instance.
17+
/// Gets the ILogger implementation used for this instance.
1818
/// </summary>
1919
protected ILogger Logger { get; private set; }
2020

2121
/// <summary>
22-
///
22+
///
2323
/// </summary>
2424
/// <param name="logger">An ILogger implementation used for writing log messages.</param>
2525
public PromptHandler(ILogger logger)

src/PowerShellEditorServices/PowerShellEditorServices.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<AssemblyTitle>PowerShell Editor Services</AssemblyTitle>
55
<Description>Provides common PowerShell editor capabilities as a .NET library.</Description>
6-
<TargetFrameworks>net451;netstandard1.6</TargetFrameworks>
6+
<TargetFrameworks>netstandard1.6;net451</TargetFrameworks>
77
<AssemblyName>Microsoft.PowerShell.EditorServices</AssemblyName>
88
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.6' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
99
</PropertyGroup>
@@ -61,6 +61,10 @@
6161

6262
<ItemGroup>
6363
<PackageReference Include="UnixConsoleEcho" Version="0.1.0" />
64+
<PackageReference Include="Serilog" Version="2.7.1" />
65+
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
66+
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
67+
<PackageReference Include="Serilog.Sinks.Async" Version="1.2.0" />
6468
</ItemGroup>
6569

6670
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">

src/PowerShellEditorServices/Session/Capabilities/DscBreakpointCapability.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,4 @@ public static DscBreakpointCapability CheckForCapability(
162162
return capability;
163163
}
164164
}
165-
}
165+
}

0 commit comments

Comments
 (0)