Skip to content

Commit 52e180d

Browse files
authored
Use formattable string approach to align logging API convention (#27618)
* Use formattable string approach, instead of interpolated to align with desired convention. * Fix highlight callouts
1 parent 65bbfc3 commit 52e180d

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

docs/core/extensions/snippets/workers/timer-service/TimerService.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public sealed class TimerService : IHostedService, IAsyncDisposable
1111

1212
public Task StartAsync(CancellationToken stoppingToken)
1313
{
14-
_logger.LogInformation($"{nameof(TimerHostedService)} is running.");
14+
_logger.LogInformation("{Service} is running.", nameof(TimerHostedService));
1515
_timer = new Timer(DoWork, null, TimeSpan.Zero, TimeSpan.FromSeconds(5));
1616

1717
return _completedTask;
@@ -22,14 +22,15 @@ private void DoWork(object? state)
2222
int count = Interlocked.Increment(ref _executionCount);
2323

2424
_logger.LogInformation(
25-
$"{nameof(TimerHostedService)} is working, execution count: {{Count:#,0}}",
25+
"{Service} is working, execution count: {{Count:#,0}}",
26+
nameof(TimerHostedService),
2627
count);
2728
}
2829

2930
public Task StopAsync(CancellationToken stoppingToken)
3031
{
3132
_logger.LogInformation(
32-
$"{nameof(TimerHostedService)} is stopping.");
33+
"{Service} is stopping.", nameof(TimerHostedService));
3334

3435
_timer?.Change(Timeout.Infinite, 0);
3536

docs/core/extensions/timer-service.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Implement the IHostedService interface
33
description: Learn how to implement a custom IHostedService interface with .NET.
44
author: IEvangelist
55
ms.author: dapine
6-
ms.date: 11/12/2021
6+
ms.date: 12/17/2021
77
ms.topic: tutorial
88
---
99

@@ -36,7 +36,7 @@ The timer-based background service makes use of the <xref:System.Threading.Timer
3636

3737
Replace the contents of the `Worker` from the template with the following C# code, and rename the file to *TimerService.cs*:
3838

39-
:::code source="snippets/workers/timer-service/TimerService.cs" highlight="34,41-44":::
39+
:::code source="snippets/workers/timer-service/TimerService.cs" highlight="35,42-45":::
4040

4141
> [!IMPORTANT]
4242
> The `Worker` was a subclass of <xref:Microsoft.Extensions.Hosting.BackgroundService>. Now, the `TimerService` implements both the <xref:Microsoft.Extensions.Hosting.IHostedService>, and <xref:System.IAsyncDisposable> interfaces.

0 commit comments

Comments
 (0)