Skip to content

Commit

Permalink
Use formattable string approach to align logging API convention (dotn…
Browse files Browse the repository at this point in the history
…et#27618)

* Use formattable string approach, instead of interpolated to align with desired convention.

* Fix highlight callouts
  • Loading branch information
IEvangelist authored Dec 17, 2021
1 parent 65bbfc3 commit 52e180d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public sealed class TimerService : IHostedService, IAsyncDisposable

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

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

_logger.LogInformation(
$"{nameof(TimerHostedService)} is working, execution count: {{Count:#,0}}",
"{Service} is working, execution count: {{Count:#,0}}",
nameof(TimerHostedService),
count);
}

public Task StopAsync(CancellationToken stoppingToken)
{
_logger.LogInformation(
$"{nameof(TimerHostedService)} is stopping.");
"{Service} is stopping.", nameof(TimerHostedService));

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

Expand Down
4 changes: 2 additions & 2 deletions docs/core/extensions/timer-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Implement the IHostedService interface
description: Learn how to implement a custom IHostedService interface with .NET.
author: IEvangelist
ms.author: dapine
ms.date: 11/12/2021
ms.date: 12/17/2021
ms.topic: tutorial
---

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

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

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

> [!IMPORTANT]
> 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.
Expand Down

0 comments on commit 52e180d

Please sign in to comment.