Skip to content

Commit 7a4424a

Browse files
authored
Improve InternalLogger output when connect fails with ServiceUri (#151)
1 parent 5a66baa commit 7a4424a

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

src/NLog.Extensions.AzureBlobStorage/BlobStorageTarget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ protected override void InitializeTarget()
173173
}
174174
catch (Exception ex)
175175
{
176-
if (string.IsNullOrEmpty(connectionString) && !string.IsNullOrEmpty(serviceUri))
176+
if (!string.IsNullOrEmpty(serviceUri))
177177
InternalLogger.Error(ex, "AzureBlobStorageTarget(Name={0}): Failed to create BlobClient with ServiceUri={1}.", Name, serviceUri);
178178
else
179179
InternalLogger.Error(ex, "AzureBlobStorageTarget(Name={0}): Failed to create BlobClient with connectionString={1}.", Name, connectionString);

src/NLog.Extensions.AzureDataTables/DataTablesTarget.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,11 @@ protected override void InitializeTarget()
170170
}
171171
catch (Exception ex)
172172
{
173-
InternalLogger.Error(ex, "AzureDataTablesTarget(Name={0}): Failed to create TableClient with connectionString={1}.", Name, connectionString);
174-
throw;
173+
if (!string.IsNullOrEmpty(serviceUri))
174+
InternalLogger.Error(ex, "AzureDataTablesTarget(Name={0}): Failed to create TableClient with ServiceUri={1}.", Name, serviceUri);
175+
else
176+
InternalLogger.Error(ex, "AzureDataTablesTarget(Name={0}): Failed to create TableClient with ConnectionString={1}.", Name, connectionString);
177+
throw;
175178
}
176179
}
177180

src/NLog.Extensions.AzureEventHub/EventHubTarget.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ protected override void InitializeTarget()
187187
}
188188
catch (Exception ex)
189189
{
190-
InternalLogger.Error(ex, "AzureEventHubTarget(Name={0}): Failed to create EventHubClient with connectionString={1} to EventHubName={2}.", Name, connectionString, eventHubName);
190+
if (!string.IsNullOrEmpty(serviceUri))
191+
InternalLogger.Error(ex, "AzureEventHubTarget(Name={0}): Failed to create EventHubClient with EventHubName={1} and ServiceUri={2}.", Name, eventHubName, serviceUri);
192+
else
193+
InternalLogger.Error(ex, "AzureEventHubTarget(Name={0}): Failed to create EventHubClient with EventHubName={1} and ConnectionString={2}", Name, eventHubName, connectionString);
191194
throw;
192195
}
193196
}

src/NLog.Extensions.AzureQueueStorage/QueueStorageTarget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ protected override void InitializeTarget()
159159
}
160160
catch (Exception ex)
161161
{
162-
if (string.IsNullOrEmpty(connectionString) && !string.IsNullOrEmpty(serviceUri))
162+
if (!string.IsNullOrEmpty(serviceUri))
163163
InternalLogger.Error(ex, "AzureQueueStorageTarget(Name={0}): Failed to create QueueClient with ServiceUri={1}.", Name, serviceUri);
164164
else
165165
InternalLogger.Error(ex, "AzureQueueStorageTarget(Name={0}): Failed to create QueueClient with connectionString={1}.", Name, connectionString);

src/NLog.Extensions.AzureServiceBus/ServiceBusTarget.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ protected override void InitializeTarget()
223223
}
224224
catch (Exception ex)
225225
{
226-
InternalLogger.Error(ex, "AzureServiceBusTarget(Name={0}): Failed to create ServiceBusClient with connectionString={1} and EntityPath={2}.", Name, connectionString, queueOrTopicName);
226+
if (!string.IsNullOrEmpty(serviceUri))
227+
InternalLogger.Error(ex, "AzureServiceBusTarget(Name={0}): Failed to create ServiceBusClient with EntityPath={1} and ServiceUri={2}", Name, queueOrTopicName, serviceUri);
228+
else
229+
InternalLogger.Error(ex, "AzureServiceBusTarget(Name={0}): Failed to create ServiceBusClient with EntityPath={1} and ConnectionString={2}", Name, queueOrTopicName, connectionString);
227230
throw;
228231
}
229232
}

0 commit comments

Comments
 (0)