# ResourceLoggerService Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [ResourceLoggerService](/reference/api/csharp/aspire.hosting/resourceloggerservice.md)
- Kind: `Methods`
- Members: `11`

A service that provides loggers for resources to write to.

## ClearBacklog(string)

- Name: `ClearBacklog(string)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs#L304-L310)

Clears the log stream's backlog for the resource.

```csharp
public class ResourceLoggerService
{
    public void ClearBacklog(
        string resourceName)
    {
        // ...
    }
}
```

## Parameters

- `resourceName` (`string`)

## Complete(IResource)

- Name: `Complete(IResource)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs#L273-L283)

Completes the log stream for the resource.

```csharp
public class ResourceLoggerService
{
    public void Complete(
        IResource resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The [IResource](/reference/api/csharp/aspire.hosting/iresource.md).

## Complete(string)

- Name: `Complete(string)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs#L291-L297)

Completes the log stream for the resource.

```csharp
public class ResourceLoggerService
{
    public void Complete(
        string name)
    {
        // ...
    }
}
```

## Parameters

- `name` (`string`)
  The name of the resource.

## Dispose

- Name: `Dispose`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs#L639-L653)

Disposes the service and completes all log streams.

```csharp
public class ResourceLoggerService
{
    public void Dispose()
    {
        // ...
    }
}
```

## GetAllAsync(IResource)

- Name: `GetAllAsync(IResource)`
- Returns: `IAsyncEnumerable<IReadOnlyList<LogLine>>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs#L159-L168)

Get all logs for a resource. This will return all logs that have been written to the log stream for the resource and then complete.

```csharp
public class ResourceLoggerService
{
    public IAsyncEnumerable<IReadOnlyList<LogLine>> GetAllAsync(
        IResource resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to get all logs for.

## Returns

`IAsyncEnumerable<IReadOnlyList<LogLine>>` -- An async enumerable that returns all logs that have been written to the log stream and then completes.

## GetAllAsync(string)

- Name: `GetAllAsync(string)`
- Returns: `IAsyncEnumerable<IReadOnlyList<LogLine>>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs#L199-L201)

Get all logs for a resource. This will return all logs that have been written to the log stream for the resource and then complete.

```csharp
public class ResourceLoggerService
{
    public IAsyncEnumerable<IReadOnlyList<LogLine>> GetAllAsync(
        string resourceName)
    {
        // ...
    }
}
```

## Parameters

- `resourceName` (`string`)
  The resource name

## Returns

`IAsyncEnumerable<IReadOnlyList<LogLine>>` -- An async enumerable that returns all logs that have been written to the log stream and then completes.

## GetLogger(IResource)

- Name: `GetLogger(IResource)`
- Returns: `ILogger`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs#L51-L67)

Gets the logger for the resource to write to.

```csharp
public class ResourceLoggerService
{
    public ILogger GetLogger(
        IResource resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource name

## Returns

`ILogger` -- An `Logging.ILogger` which represents the resource.

## GetLogger(string)

- Name: `GetLogger(string)`
- Returns: `ILogger`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs#L135-L137)

Gets the logger for the resource to write to.

```csharp
public class ResourceLoggerService
{
    public ILogger GetLogger(
        string resourceName)
    {
        // ...
    }
}
```

## Parameters

- `resourceName` (`string`)
  The name of the resource from the Aspire application model.

## Returns

`ILogger` -- An `Logging.ILogger` which represents the named resource.

## WatchAnySubscribersAsync(CancellationToken)

- Name: `WatchAnySubscribersAsync(CancellationToken)`
- Returns: [IAsyncEnumerable<LogSubscriber>](/reference/api/csharp/aspire.hosting/logsubscriber.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs#L225-L265)

Watch for subscribers to the log stream for a resource.

```csharp
public class ResourceLoggerService
{
    public IAsyncEnumerable<LogSubscriber> WatchAnySubscribersAsync(
        CancellationToken cancellationToken = default(CancellationToken))
    {
        // ...
    }
}
```

## Parameters

- `cancellationToken` (`CancellationToken`) `optional`

## Returns

[IAsyncEnumerable<LogSubscriber>](/reference/api/csharp/aspire.hosting/logsubscriber.md) -- An async enumerable that returns when the first subscriber is added to a log, or when the last subscriber is removed.

## WatchAsync(IResource)

- Name: `WatchAsync(IResource)`
- Returns: `IAsyncEnumerable<IReadOnlyList<LogLine>>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs#L179-L188)

Watch for changes to the log stream for a resource.

```csharp
public class ResourceLoggerService
{
    public IAsyncEnumerable<IReadOnlyList<LogLine>> WatchAsync(
        IResource resource)
    {
        // ...
    }
}
```

## Parameters

- `resource` ([IResource](/reference/api/csharp/aspire.hosting/iresource.md))
  The resource to watch for logs.

## Returns

`IAsyncEnumerable<IReadOnlyList<LogLine>>` -- An async enumerable that returns the logs as they are written.

## WatchAsync(string)

- Name: `WatchAsync(string)`
- Returns: `IAsyncEnumerable<IReadOnlyList<LogLine>>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/ResourceLoggerService.cs#L211-L213)

Watch for changes to the log stream for a resource.

```csharp
public class ResourceLoggerService
{
    public IAsyncEnumerable<IReadOnlyList<LogLine>> WatchAsync(
        string resourceName)
    {
        // ...
    }
}
```

## Parameters

- `resourceName` (`string`)
  The resource name

## Returns

`IAsyncEnumerable<IReadOnlyList<LogLine>>` -- An async enumerable that returns the logs as they are written.
