Skip to content

Commit d4d8552

Browse files
committed
Add logger to cli
1 parent 82f4f95 commit d4d8552

File tree

4 files changed

+158
-25
lines changed

4 files changed

+158
-25
lines changed

src/EasySign.Cli/BundleCommandProvider.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@
55
using System.Text;
66
using System.Threading.Tasks;
77

8+
using Microsoft.Extensions.Logging;
9+
810
using SAPTeam.EasySign.CommandLine;
911

1012
namespace SAPTeam.EasySign.Cli
1113
{
1214
internal class BundleCommandProvider : CommandProvider<Bundle>
1315
{
16+
ILogger _logger;
17+
18+
public BundleCommandProvider(ILogger logger)
19+
{
20+
_logger = logger;
21+
}
22+
1423
public override void InitializeBundle(string bundlePath)
1524
{
16-
Bundle = new Bundle(bundlePath);
25+
Bundle = new Bundle(bundlePath, _logger);
1726
}
1827

1928
public override RootCommand GetRootCommand()

src/EasySign.Cli/EasySign.Cli.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
<ItemGroup>
3131
<PackageReference Include="Nerdbank.GitVersioning" Version="3.7.115" PrivateAssets="All" />
32+
<PackageReference Include="Serilog" Version="4.2.0" />
33+
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.1" />
34+
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
3235
</ItemGroup>
3336

3437
<ItemGroup>

src/EasySign.Cli/Program.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
using System.Security.Cryptography.X509Certificates;
66
using System.Text;
77

8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Logging;
10+
11+
using Serilog;
12+
813
using Spectre.Console;
914

1015
namespace SAPTeam.EasySign.Cli
@@ -13,8 +18,28 @@ internal class Program
1318
{
1419
static int Main(string[] args)
1520
{
16-
var root = new BundleCommandProvider().GetRootCommand();
17-
return root.Invoke(args);
21+
Log.Logger = new LoggerConfiguration()
22+
.WriteTo.File(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logs/log-.txt"), rollingInterval: RollingInterval.Day, shared: true)
23+
.MinimumLevel.Debug() // Minimum log level
24+
.CreateLogger();
25+
26+
var serviceCollection = new ServiceCollection();
27+
serviceCollection.AddLogging(configure =>
28+
{
29+
configure.ClearProviders(); // Clear default providers
30+
configure.AddSerilog();
31+
});
32+
33+
var serviceProvider = serviceCollection.BuildServiceProvider();
34+
35+
// Resolve an ILogger instance
36+
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
37+
logger.BeginScope("EasySign.Cli started at " + DateTime.Now);
38+
39+
var root = new BundleCommandProvider(logger).GetRootCommand();
40+
var exitCode = root.Invoke(args);
41+
42+
return exitCode;
1843
}
1944

2045
}

src/EasySign.Cli/packages.lock.json

Lines changed: 118 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,87 @@
88
"resolved": "3.7.115",
99
"contentHash": "EpXamaAdRfG/BMxGgvZlTM0npRnkmXUjAj8OdNKd17t4oN+2nvjdv/KnFmzOOMDqvlwB49UCwtOHJrAQTfUBtQ=="
1010
},
11+
"Serilog": {
12+
"type": "Direct",
13+
"requested": "[4.2.0, )",
14+
"resolved": "4.2.0",
15+
"contentHash": "gmoWVOvKgbME8TYR+gwMf7osROiWAURterc6Rt2dQyX7wtjZYpqFiA/pY6ztjGQKKV62GGCyOcmtP1UKMHgSmA=="
16+
},
17+
"Serilog.Extensions.Logging": {
18+
"type": "Direct",
19+
"requested": "[9.0.1, )",
20+
"resolved": "9.0.1",
21+
"contentHash": "IZo04/stVuOBhe0jzIe+6gVmiZ50i1cDljTnDyz6lqM7rbNhrHsPWg3IraJIvzZBihYPg5V9TVQYgRnm3xX8eA==",
22+
"dependencies": {
23+
"Microsoft.Extensions.Logging": "9.0.0",
24+
"Serilog": "4.2.0"
25+
}
26+
},
27+
"Serilog.Sinks.File": {
28+
"type": "Direct",
29+
"requested": "[6.0.0, )",
30+
"resolved": "6.0.0",
31+
"contentHash": "lxjg89Y8gJMmFxVkbZ+qDgjl+T4yC5F7WSLTvA+5q0R04tfKVLRL/EHpYoJ/MEQd2EeCKDuylBIVnAYMotmh2A==",
32+
"dependencies": {
33+
"Serilog": "4.0.0"
34+
}
35+
},
1136
"Ensure.That": {
1237
"type": "Transitive",
1338
"resolved": "10.1.0",
1439
"contentHash": "rzTMSs0lQnu0WsesvTjs/zDzqiZXb9r5dv+wFQcPg/iIZqXb5BzwpIWEwi8Q3HA0TS4ytRcY129aSek6IzuOmA=="
1540
},
1641
"Microsoft.Extensions.DependencyInjection": {
1742
"type": "Transitive",
18-
"resolved": "8.0.1",
19-
"contentHash": "BmANAnR5Xd4Oqw7yQ75xOAYODybZQRzdeNucg7kS5wWKd2PNnMdYtJ2Vciy0QLylRmv42DGl5+AFL9izA6F1Rw==",
43+
"resolved": "9.0.0",
44+
"contentHash": "MCPrg7v3QgNMr0vX4vzRXvkNGgLg8vKWX0nKCWUxu2uPyMsaRgiRc1tHBnbTcfJMhMKj2slE/j2M9oGkd25DNw==",
2045
"dependencies": {
21-
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.2"
46+
"Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.0"
2247
}
2348
},
2449
"Microsoft.Extensions.DependencyInjection.Abstractions": {
2550
"type": "Transitive",
26-
"resolved": "8.0.2",
27-
"contentHash": "3iE7UF7MQkCv1cxzCahz+Y/guQbTqieyxyaWKhrRO91itI9cOKO76OHeQDahqG4MmW5umr3CcCvGmK92lWNlbg=="
51+
"resolved": "9.0.0",
52+
"contentHash": "+6f2qv2a3dLwd5w6JanPIPs47CxRbnk+ZocMJUhv9NxP88VlOcJYZs9jY+MYSjxvady08bUZn6qgiNh7DadGgg=="
2853
},
2954
"Microsoft.Extensions.Logging": {
3055
"type": "Transitive",
31-
"resolved": "8.0.1",
32-
"contentHash": "4x+pzsQEbqxhNf1QYRr5TDkLP9UsLT3A6MdRKDDEgrW7h1ljiEPgTNhKYUhNCCAaVpQECVQ+onA91PTPnIp6Lw==",
56+
"resolved": "9.0.0",
57+
"contentHash": "crjWyORoug0kK7RSNJBTeSE6VX8IQgLf3nUpTB9m62bPXp/tzbnOsnbe8TXEG0AASNaKZddnpHKw7fET8E++Pg==",
3358
"dependencies": {
34-
"Microsoft.Extensions.DependencyInjection": "8.0.1",
35-
"Microsoft.Extensions.Logging.Abstractions": "8.0.2",
36-
"Microsoft.Extensions.Options": "8.0.2"
59+
"Microsoft.Extensions.DependencyInjection": "9.0.0",
60+
"Microsoft.Extensions.Logging.Abstractions": "9.0.0",
61+
"Microsoft.Extensions.Options": "9.0.0",
62+
"System.Diagnostics.DiagnosticSource": "9.0.0"
3763
}
3864
},
3965
"Microsoft.Extensions.Logging.Abstractions": {
4066
"type": "Transitive",
41-
"resolved": "8.0.2",
42-
"contentHash": "nroMDjS7hNBPtkZqVBbSiQaQjWRDxITI8Y7XnDs97rqG3EbzVTNLZQf7bIeUJcaHOV8bca47s1Uxq94+2oGdxA==",
67+
"resolved": "9.0.0",
68+
"contentHash": "g0UfujELzlLbHoVG8kPKVBaW470Ewi+jnptGS9KUi6jcb+k2StujtK3m26DFSGGwQ/+bVgZfsWqNzlP6YOejvw==",
4369
"dependencies": {
44-
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.2",
45-
"System.Diagnostics.DiagnosticSource": "8.0.1"
70+
"Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.0",
71+
"System.Buffers": "4.5.1",
72+
"System.Diagnostics.DiagnosticSource": "9.0.0",
73+
"System.Memory": "4.5.5"
4674
}
4775
},
4876
"Microsoft.Extensions.Options": {
4977
"type": "Transitive",
50-
"resolved": "8.0.2",
51-
"contentHash": "dWGKvhFybsaZpGmzkGCbNNwBD1rVlWzrZKANLW/CcbFJpCEceMCGzT7zZwHOGBCbwM0SzBuceMj5HN1LKV1QqA==",
78+
"resolved": "9.0.0",
79+
"contentHash": "y2146b3jrPI3Q0lokKXdKLpmXqakYbDIPDV6r3M8SqvSf45WwOTzkyfDpxnZXJsJQEpAsAqjUq5Pu8RCJMjubg==",
5280
"dependencies": {
53-
"Microsoft.Extensions.DependencyInjection.Abstractions": "8.0.0",
54-
"Microsoft.Extensions.Primitives": "8.0.0"
81+
"Microsoft.Extensions.DependencyInjection.Abstractions": "9.0.0",
82+
"Microsoft.Extensions.Primitives": "9.0.0",
83+
"System.ComponentModel.Annotations": "5.0.0"
5584
}
5685
},
5786
"Microsoft.Extensions.Primitives": {
5887
"type": "Transitive",
59-
"resolved": "8.0.0",
60-
"contentHash": "bXJEZrW9ny8vjMF1JV253WeLhpEVzFo1lyaZu1vQ4ZxWUlVvknZ/+ftFgVheLubb4eZPSwwxBeqS1JkCOjxd8g==",
88+
"resolved": "9.0.0",
89+
"contentHash": "N3qEBzmLMYiASUlKxxFIISP4AiwuPTHF5uCh+2CWSwwzAJiIYx0kBJsS30cp1nvhSySFAVi30jecD307jV+8Kg==",
6190
"dependencies": {
91+
"System.Memory": "4.5.5",
6292
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
6393
}
6494
},
@@ -67,19 +97,35 @@
6797
"resolved": "0.49.1",
6898
"contentHash": "USV+pdu49OJ3nCjxNuw1K9Zw/c1HCBbwbjXZp0EOn6wM99tFdAtN34KEBZUMyRuJuXlUMDqhd8Yq9obW2MslYA=="
6999
},
100+
"System.Buffers": {
101+
"type": "Transitive",
102+
"resolved": "4.5.1",
103+
"contentHash": "Rw7ijyl1qqRS0YQD/WycNst8hUUMgrMH4FCn1nNm27M4VxchZ1js3fVjQaANHO5f3sN4isvP4a+Met9Y4YomAg=="
104+
},
70105
"System.CommandLine": {
71106
"type": "Transitive",
72107
"resolved": "2.0.0-beta4.22272.1",
73108
"contentHash": "1uqED/q2H0kKoLJ4+hI2iPSBSEdTuhfCYADeJrAqERmiGQ2NNacYKRNEQ+gFbU4glgVyK8rxI+ZOe1onEtr/Pg=="
74109
},
110+
"System.ComponentModel.Annotations": {
111+
"type": "Transitive",
112+
"resolved": "5.0.0",
113+
"contentHash": "dMkqfy2el8A8/I76n2Hi1oBFEbG1SfxD2l5nhwXV3XjlnOmwxJlQbYpJH4W51odnU9sARCSAgv7S3CyAFMkpYg=="
114+
},
75115
"System.Diagnostics.DiagnosticSource": {
76116
"type": "Transitive",
77-
"resolved": "8.0.1",
78-
"contentHash": "vaoWjvkG1aenR2XdjaVivlCV9fADfgyhW5bZtXT23qaEea0lWiUljdQuze4E31vKM7ZWJaSUsbYIKE3rnzfZUg==",
117+
"resolved": "9.0.0",
118+
"contentHash": "ddppcFpnbohLWdYKr/ZeLZHmmI+DXFgZ3Snq+/E7SwcdW4UnvxmaugkwGywvGVWkHPGCSZjCP+MLzu23AL5SDw==",
79119
"dependencies": {
120+
"System.Memory": "4.5.5",
80121
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
81122
}
82123
},
124+
"System.Memory": {
125+
"type": "Transitive",
126+
"resolved": "4.5.5",
127+
"contentHash": "XIWiDvKPXaTveaB7HVganDlOCRoj03l+jrwNvcge/t8vhGYKvqV+dMv6G4SAX2NoNmN0wZfVPTAlFwZcZvVOUw=="
128+
},
83129
"System.Runtime.CompilerServices.Unsafe": {
84130
"type": "Transitive",
85131
"resolved": "6.0.0",
@@ -108,6 +154,31 @@
108154
"resolved": "3.7.115",
109155
"contentHash": "EpXamaAdRfG/BMxGgvZlTM0npRnkmXUjAj8OdNKd17t4oN+2nvjdv/KnFmzOOMDqvlwB49UCwtOHJrAQTfUBtQ=="
110156
},
157+
"Serilog": {
158+
"type": "Direct",
159+
"requested": "[4.2.0, )",
160+
"resolved": "4.2.0",
161+
"contentHash": "gmoWVOvKgbME8TYR+gwMf7osROiWAURterc6Rt2dQyX7wtjZYpqFiA/pY6ztjGQKKV62GGCyOcmtP1UKMHgSmA=="
162+
},
163+
"Serilog.Extensions.Logging": {
164+
"type": "Direct",
165+
"requested": "[9.0.1, )",
166+
"resolved": "9.0.1",
167+
"contentHash": "IZo04/stVuOBhe0jzIe+6gVmiZ50i1cDljTnDyz6lqM7rbNhrHsPWg3IraJIvzZBihYPg5V9TVQYgRnm3xX8eA==",
168+
"dependencies": {
169+
"Microsoft.Extensions.Logging": "9.0.0",
170+
"Serilog": "4.2.0"
171+
}
172+
},
173+
"Serilog.Sinks.File": {
174+
"type": "Direct",
175+
"requested": "[6.0.0, )",
176+
"resolved": "6.0.0",
177+
"contentHash": "lxjg89Y8gJMmFxVkbZ+qDgjl+T4yC5F7WSLTvA+5q0R04tfKVLRL/EHpYoJ/MEQd2EeCKDuylBIVnAYMotmh2A==",
178+
"dependencies": {
179+
"Serilog": "4.0.0"
180+
}
181+
},
111182
"Ensure.That": {
112183
"type": "Transitive",
113184
"resolved": "10.1.0",
@@ -197,6 +268,31 @@
197268
"resolved": "3.7.115",
198269
"contentHash": "EpXamaAdRfG/BMxGgvZlTM0npRnkmXUjAj8OdNKd17t4oN+2nvjdv/KnFmzOOMDqvlwB49UCwtOHJrAQTfUBtQ=="
199270
},
271+
"Serilog": {
272+
"type": "Direct",
273+
"requested": "[4.2.0, )",
274+
"resolved": "4.2.0",
275+
"contentHash": "gmoWVOvKgbME8TYR+gwMf7osROiWAURterc6Rt2dQyX7wtjZYpqFiA/pY6ztjGQKKV62GGCyOcmtP1UKMHgSmA=="
276+
},
277+
"Serilog.Extensions.Logging": {
278+
"type": "Direct",
279+
"requested": "[9.0.1, )",
280+
"resolved": "9.0.1",
281+
"contentHash": "IZo04/stVuOBhe0jzIe+6gVmiZ50i1cDljTnDyz6lqM7rbNhrHsPWg3IraJIvzZBihYPg5V9TVQYgRnm3xX8eA==",
282+
"dependencies": {
283+
"Microsoft.Extensions.Logging": "9.0.0",
284+
"Serilog": "4.2.0"
285+
}
286+
},
287+
"Serilog.Sinks.File": {
288+
"type": "Direct",
289+
"requested": "[6.0.0, )",
290+
"resolved": "6.0.0",
291+
"contentHash": "lxjg89Y8gJMmFxVkbZ+qDgjl+T4yC5F7WSLTvA+5q0R04tfKVLRL/EHpYoJ/MEQd2EeCKDuylBIVnAYMotmh2A==",
292+
"dependencies": {
293+
"Serilog": "4.0.0"
294+
}
295+
},
200296
"Ensure.That": {
201297
"type": "Transitive",
202298
"resolved": "10.1.0",

0 commit comments

Comments
 (0)