# Google.Cloud.Diagnostics.Common - Class BufferOptions (5.3.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [5.3.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions)
- [5.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.2.0/Google.Cloud.Diagnostics.Common.BufferOptions)
- [5.1.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.1.0/Google.Cloud.Diagnostics.Common.BufferOptions)
- [5.0.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.0.0/Google.Cloud.Diagnostics.Common.BufferOptions)
- [4.4.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/4.4.0/Google.Cloud.Diagnostics.Common.BufferOptions)
- [4.3.1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/4.3.1/Google.Cloud.Diagnostics.Common.BufferOptions)

    public sealed class BufferOptions

Reference documentation and code samples for the Google.Cloud.Diagnostics.Common class BufferOptions.

Options that define a buffer.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> BufferOptions

## Inherited Members

[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Cloud.Diagnostics.Common](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common)

## Assembly

Google.Cloud.Diagnostics.Common.dll

## Properties

### BufferSizeBytes

    public int BufferSizeBytes { get; }

The size of the buffer in bytes, only used for [Sized](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType#Google_Cloud_Diagnostics_Common_BufferType_Sized)

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int32` |   |

### BufferType

    public BufferType BufferType { get; }

The type of buffer to be used.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType` |   |

### BufferWaitTime

    public TimeSpan BufferWaitTime { get; }

The time to wait before the buffer is flushed, only used for [Timed](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType#Google_Cloud_Diagnostics_Common_BufferType_Timed)

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.timespan` |   |

### TimerExceptionHandler

    public Action<Exception> TimerExceptionHandler { get; }

An action that will be called whenever an exception is thrown during a timed flush of the buffer.
May be null. Only used for [Timed](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType#Google_Cloud_Diagnostics_Common_BufferType_Timed).

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.action-1https://learn.microsoft.com/dotnet/api/system.exception` |   |

**Remarks** Throwing an exception within the timer thread risks inmediately crashing the applicaiton, so we
never do that, even if [ExceptionHandling](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryOptions#Google_Cloud_Diagnostics_Common_RetryOptions_ExceptionHandling) has been set to
[Propagate](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.ExceptionHandling#Google_Cloud_Diagnostics_Common_ExceptionHandling_Propagate) because propagating exceptions is different than crashing
an application.
Instead, client code can specify a value for this action, that will be called when an exception is thrown
within the timer thread. Client code may decide what to do in such cases.

## Methods

### NoBuffer()

    public static BufferOptions NoBuffer()

Create [BufferOptions](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions) for [None](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType#Google_Cloud_Diagnostics_Common_BufferType_None)

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions` |   |

### SizedBuffer(int)

    public static BufferOptions SizedBuffer(int bufferSizeBytes = 65536)

Create [BufferOptions](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions) for [Sized](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType#Google_Cloud_Diagnostics_Common_BufferType_Sized)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bufferSizeBytes` | `https://learn.microsoft.com/dotnet/api/system.int32` Optional, The buffer size in bytes. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions` |   |

### TimedBuffer(TimeSpan?)

    public static BufferOptions TimedBuffer(TimeSpan? bufferWaitTime = null)

Create [BufferOptions](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions) for [Timed](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType#Google_Cloud_Diagnostics_Common_BufferType_Timed)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `bufferWaitTime` | `https://learn.microsoft.com/dotnet/api/system.timespan` Optional, The minimum amount of time between flushes. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions` |   |

### WithTimerExceptionHandler(Action\<Exception\>)

    public BufferOptions WithTimerExceptionHandler(Action<Exception> handler)

Creates a new [BufferOptions](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions) instance which is identical to this one
but with the given timer exception handler.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `handler` | `https://learn.microsoft.com/dotnet/api/system.action-1https://learn.microsoft.com/dotnet/api/system.exception` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions` |   |