From 15f8f1fda6f9530a5a84fcdb51c354db452a311b Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Thu, 29 Oct 2015 15:25:10 +0100 Subject: [PATCH] Add direction information to exception logging References #1 --- .../MainWindowViewModel.cs | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Lawo.GlowAnalyzerProxy.Main/MainWindowViewModel.cs b/Lawo.GlowAnalyzerProxy.Main/MainWindowViewModel.cs index f7813ccb..77c6e7d7 100644 --- a/Lawo.GlowAnalyzerProxy.Main/MainWindowViewModel.cs +++ b/Lawo.GlowAnalyzerProxy.Main/MainWindowViewModel.cs @@ -355,29 +355,36 @@ private async Task ForwardLoop(TcpListener listener) try { - using (this.ConsumerConnection.Client = await listener.AcceptTcpClientAsync()) - { - listener.Stop(); + this.ConsumerConnection.Client = await listener.AcceptTcpClientAsync(); + listener.Stop(); + } + catch (Exception ex) + { + await EnqueueLogOperationAsync( + logInfo, "Exception", null, null, i => i.Logger.LogException("Consumer to Proxy", ex)); + } + using (this.ConsumerConnection.Client) + { + try + { using (this.ProviderConnection.Client = await ConnectToProvider()) { await Task.WhenAll( this.ForwardFromConsumerAsync(logInfo), this.ForwardFromProviderAsync(logInfo)); } } + catch (Exception ex) + { + await EnqueueLogOperationAsync( + logInfo, "Exception", null, null, i => i.Logger.LogException("Proxy to Provider", ex)); + } } - catch (Exception ex) - { - await EnqueueLogOperationAsync( - logInfo, "Exception", null, null, i => i.Logger.LogException(null, ex)); - } - finally - { - this.ConsumerConnection.Client = null; - this.ProviderConnection.Client = null; - await EnqueueLogOperationAsync(logInfo, null, null, null, i => { i.Dispose(); return new EventInfo(); }); - listener.Start(); - } + + this.ConsumerConnection.Client = null; + this.ProviderConnection.Client = null; + await EnqueueLogOperationAsync(logInfo, null, null, null, i => { i.Dispose(); return new EventInfo(); }); + listener.Start(); } else { @@ -450,6 +457,11 @@ await this.EnqueueLogOperationAsync( catch (ObjectDisposedException) { } + catch (Exception ex) + { + await EnqueueLogOperationAsync( + logInfo, "Exception", shortDirection, null, i => i.Logger.LogException(direction, ex)); + } finally { payloadStream.Dispose();