Skip to content

Commit e726b8d

Browse files
committed
Logging improvements
1 parent 01d6bd8 commit e726b8d

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/Foundatio.TestHarness/Messaging/MessageBusTestBase.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
44
using System.Linq;
@@ -49,13 +49,15 @@ public virtual async Task CanUseMessageOptionsAsync()
4949
{
5050
ShouldListenTo = s => s.Name == FoundatioDiagnostics.ActivitySource.Name,
5151
Sample = (ref ActivityCreationOptions<ActivityContext> _) => ActivitySamplingResult.AllDataAndRecorded,
52-
ActivityStarted = activity => _logger.LogInformation("Start: " + activity.DisplayName),
53-
ActivityStopped = activity => _logger.LogInformation("Stop: " + activity.DisplayName)
52+
ActivityStarted = activity => _logger.LogInformation("Start: {ActivityDisplayName}", activity.DisplayName),
53+
ActivityStopped = activity => _logger.LogInformation("Stop: {ActivityDisplayName}", activity.DisplayName),
5454
};
5555

5656
ActivitySource.AddActivityListener(listener);
5757

5858
using var activity = FoundatioDiagnostics.ActivitySource.StartActivity("Parent");
59+
Assert.NotNull(activity);
60+
Assert.NotNull(Activity.Current);
5961
Assert.Equal(Activity.Current, activity);
6062

6163
var countdown = new AsyncCountdownEvent(1);

src/Foundatio.TestHarness/Utility/InMemoryMetrics.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public class InMemoryMetrics : IDisposable
2727
private readonly AsyncAutoResetEvent _measurementEvent = new(false);
2828
private readonly ILogger _logger;
2929

30-
public InMemoryMetrics(string metricNameOrPrefix, ILogger logger, int maxMeasurementCountPerType = 100000) : this(n => n.StartsWith(metricNameOrPrefix), logger, maxMeasurementCountPerType) { }
30+
public InMemoryMetrics(string metricNameOrPrefix, ILogger logger, int maxMeasurementCountPerType = 100000) : this(
31+
n => n.StartsWith(metricNameOrPrefix), logger, maxMeasurementCountPerType)
32+
{
33+
}
3134

3235
public InMemoryMetrics(Func<string, bool> shouldCollect, ILogger logger, int maxMeasurementCountPerType = 100000)
3336
{
@@ -102,6 +105,7 @@ public InMemoryMetrics(Func<string, bool> shouldCollect, ILogger logger, int max
102105

103106
public void RecordObservableInstruments()
104107
{
108+
_logger.LogTrace("Recording observable instruments");
105109
_meterListener.RecordObservableInstruments();
106110
}
107111

src/Foundatio/Lock/ThrottlingLockProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public async Task<ILock> AcquireAsync(string resource, TimeSpan? timeUntilExpire
5050
try
5151
{
5252
_logger.LogTrace("Current time: {CurrentTime} throttle: {ThrottlingPeriod} key: {Key}", _timeProvider.GetUtcNow().ToString("mm:ss.fff"), _timeProvider.GetUtcNow().UtcDateTime.Floor(_throttlingPeriod).ToString("mm:ss.fff"), cacheKey);
53-
var hitCount = await _cacheClient.GetAsync<long?>(cacheKey, 0).AnyContext();
53+
long? hitCount = await _cacheClient.GetAsync<long?>(cacheKey, 0).AnyContext();
5454

5555
_logger.LogTrace("Current hit count: {HitCount} max: {MaxHitsPerPeriod}", hitCount, _maxHitsPerPeriod);
5656
if (hitCount <= _maxHitsPerPeriod - 1)
@@ -64,11 +64,11 @@ public async Task<ILock> AcquireAsync(string resource, TimeSpan? timeUntilExpire
6464
break;
6565
}
6666

67-
_logger.LogTrace("Max hits exceeded after increment for {Resource}.", resource);
67+
_logger.LogTrace("Max hits exceeded after increment for {Resource}", resource);
6868
}
6969
else
7070
{
71-
_logger.LogTrace("Max hits exceeded for {Resource}.", resource);
71+
_logger.LogTrace("Max hits exceeded for {Resource}", resource);
7272
}
7373

7474
if (cancellationToken.IsCancellationRequested)

src/Foundatio/Queues/InMemoryQueue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ protected override Task<IEnumerable<T>> GetDeadletterItemsImplAsync(Cancellation
352352

353353
public override Task DeleteQueueAsync()
354354
{
355-
_logger.LogTrace("Deleting queue: {QueueName}", _options.Name);
355+
_logger.LogTrace("Deleting queue: {QueueName} ({QueueId})", _options.Name, QueueId);
356356

357357
_queue.Clear();
358358
_deadletterQueue.Clear();

0 commit comments

Comments
 (0)