-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ namespace Microsoft.ApplicationInsights.NLogTarget | |
public sealed class ApplicationInsightsTarget : TargetWithLayout | ||
{ | ||
private TelemetryClient telemetryClient; | ||
private DateTime lastLogEventTime; | ||
private NLog.Layouts.Layout instrumentationKeyLayout = string.Empty; | ||
private NLog.Layouts.Layout connectionStringLayout = string.Empty; | ||
|
||
|
@@ -68,12 +67,9 @@ public string ConnectionString | |
public IList<TargetPropertyWithContext> ContextProperties { get; } = new List<TargetPropertyWithContext>(); | ||
|
||
/// <summary> | ||
/// Gets the logging controller we will be using. | ||
/// Gets or sets the factory for creating TelemetryClient, so unit-tests can assign in-memory-channel | ||
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net472)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net472)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net472)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net472)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net462)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net462)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net462)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net462)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net452)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net452)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net452)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net452)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net481)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net481)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net481)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net481)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net480)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net480)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net480)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net480)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, netcoreapp3.1)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, netcoreapp3.1)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, netcoreapp3.1)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, netcoreapp3.1)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net8.0)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net8.0)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net8.0)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net8.0)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net7.0)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net7.0)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net7.0)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net7.0)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net6.0)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net6.0)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net6.0)
Check failure on line 70 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net6.0)
|
||
/// </summary> | ||
internal TelemetryClient TelemetryClient | ||
{ | ||
get { return this.telemetryClient; } | ||
} | ||
internal Func<TelemetryConfiguration, TelemetryClient> TelemetryClientFactory { get; set; } = new Func<TelemetryConfiguration, TelemetryClient>((cfg) => new TelemetryClient(cfg)); | ||
|
||
internal void BuildPropertyBag(LogEventInfo logEvent, ITelemetry trace) | ||
{ | ||
|
@@ -134,7 +130,7 @@ protected override void InitializeTarget() | |
{ | ||
var telemetryConfiguration = TelemetryConfiguration.CreateDefault(); | ||
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net472)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net472)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net472)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net472)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net462)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net462)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net462)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net462)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net452)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net452)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net452)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net452)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net481)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net481)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net481)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net481)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net480)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net480)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net480)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net480)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, netcoreapp3.1)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, netcoreapp3.1)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, netcoreapp3.1)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, netcoreapp3.1)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net8.0)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net8.0)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net8.0)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net8.0)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net7.0)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net7.0)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net7.0)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net7.0)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net6.0)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net6.0)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net6.0)
Check warning on line 131 in LOGGING/src/NLogTarget/ApplicationInsightsTarget.cs GitHub Actions / build-test-LOGGING (windows-latest, net6.0)
|
||
telemetryConfiguration.ConnectionString = connectionString; | ||
this.telemetryClient = new TelemetryClient(telemetryConfiguration); | ||
this.telemetryClient = this.TelemetryClientFactory(telemetryConfiguration); | ||
} | ||
else | ||
{ | ||
|
@@ -162,8 +158,6 @@ protected override void Write(LogEventInfo logEvent) | |
throw new ArgumentNullException(nameof(logEvent)); | ||
} | ||
|
||
this.lastLogEventTime = DateTime.UtcNow; | ||
|
||
if (logEvent.Exception != null) | ||
{ | ||
this.SendException(logEvent); | ||
|
@@ -187,7 +181,7 @@ protected override void FlushAsync(AsyncContinuation asyncContinuation) | |
|
||
try | ||
{ | ||
this.TelemetryClient.FlushAsync(System.Threading.CancellationToken.None).ContinueWith(t => asyncContinuation(t.Exception)); | ||
this.telemetryClient.FlushAsync(System.Threading.CancellationToken.None).ContinueWith(t => asyncContinuation(t.Exception)); | ||
} | ||
catch (Exception ex) | ||
{ | ||
|