Skip to content

Commit 579c6a9

Browse files
author
Jacques Kang
committed
improve debug logging
1 parent 2e7bc32 commit 579c6a9

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/IpcServiceSample.ConsoleServer/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ static void Main(string[] args)
2929
Console.ReadKey();
3030
source.Cancel();
3131
}));
32+
33+
Console.WriteLine("Server stopped.");
3234
}
3335

3436
private static IServiceCollection ConfigureServices(IServiceCollection services)

src/JKang.IpcServiceFramework.Server/IpcServiceHost.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,20 @@ public void Run()
2929
public Task RunAsync(CancellationToken cancellationToken = default(CancellationToken))
3030
{
3131
Task[] tasks = _endpoints
32-
.Select(endpoint => endpoint.ListenAsync(cancellationToken))
32+
.Select(endpoint =>
33+
{
34+
_logger.LogDebug($"Starting endpoint '{endpoint.Name}'...");
35+
36+
cancellationToken.Register(() =>
37+
{
38+
_logger.LogDebug($"Stopping endpoint '{endpoint.Name}'...");
39+
});
40+
41+
return endpoint.ListenAsync(cancellationToken).ContinueWith(_ =>
42+
{
43+
_logger.LogDebug($"Endpoint '{endpoint.Name}' stopped.");
44+
});
45+
})
3346
.ToArray();
3447
return Task.WhenAll(tasks);
3548
}

src/JKang.IpcServiceFramework.Server/NamedPipe/NamedPipeIpcServiceEndpoint.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public NamedPipeIpcServiceEndpoint(string name, IServiceProvider serviceProvider
3737

3838
return Task.Factory.StartNew(() =>
3939
{
40-
_logger.LogDebug($"Listening named pipe endpoint '{Name}'...");
40+
_logger.LogDebug($"Endpoint '{Name}' listening on pipe '{PipeName}'...");
4141
while (!cancellationToken.IsCancellationRequested)
4242
{
4343
Thread.Sleep(100);
@@ -52,7 +52,6 @@ public NamedPipeIpcServiceEndpoint(string name, IServiceProvider serviceProvider
5252
}
5353
}
5454
}
55-
_logger.LogDebug($"Shutting down named pipe endpoint '{Name}'...");
5655
});
5756
}
5857

src/JKang.IpcServiceFramework.Server/Tcp/TcpIpcServiceEndpoint.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ public TcpIpcServiceEndpoint(String name, IServiceProvider serviceProvider, IPAd
3434

3535
cancellationToken.Register(() =>
3636
{
37-
_logger.LogDebug($"Shutting down tcp endpoint '{Name}'...");
3837
_listener.Stop();
3938
});
4039

4140
return Task.Run(async () =>
4241
{
4342
try
4443
{
45-
_logger.LogDebug($"Listening tcp endpoint '{Name}' on port {Port}...");
44+
_logger.LogDebug($"Endpoint '{Name}' listening on port {Port}...");
4645
while (true)
4746
{
4847
TcpClient client = await _listener.AcceptTcpClientAsync();

0 commit comments

Comments
 (0)