Throwing an exception within the timer thread risks inmediately crashing the applicaiton, so we
never do that, even if ExceptionHandling has been set to
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThe \u003ccode\u003eBufferOptions\u003c/code\u003e class in the \u003ccode\u003eGoogle.Cloud.Diagnostics.Common\u003c/code\u003e namespace provides settings for defining a buffer used in diagnostics, offering control over its size, type, and timing.\u003c/p\u003e\n"],["\u003cp\u003eThere are several available versions of this class, with the latest being 5.2.0, allowing users to select different version based on their requirements.\u003c/p\u003e\n"],["\u003cp\u003eUsers can choose from different buffer types: \u003ccode\u003eNone\u003c/code\u003e, \u003ccode\u003eSized\u003c/code\u003e, or \u003ccode\u003eTimed\u003c/code\u003e, with each type having properties to configure buffer size, wait time, and an exception handler.\u003c/p\u003e\n"],["\u003cp\u003eThe class provides static methods like \u003ccode\u003eNoBuffer()\u003c/code\u003e, \u003ccode\u003eSizedBuffer()\u003c/code\u003e, and \u003ccode\u003eTimedBuffer()\u003c/code\u003e to easily create \u003ccode\u003eBufferOptions\u003c/code\u003e instances for each of the different buffer types.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eWithTimerExceptionHandler()\u003c/code\u003e method allows users to define a custom action to handle exceptions that occur during timed buffer flushes.\u003c/p\u003e\n"]]],[],null,["# Google.Cloud.Diagnostics.Common - Class BufferOptions (5.3.0)\n\nVersion latestkeyboard_arrow_down\n\n- [5.3.0 (latest)](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions)\n- [5.2.0](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.2.0/Google.Cloud.Diagnostics.Common.BufferOptions)\n- [5.1.0](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.1.0/Google.Cloud.Diagnostics.Common.BufferOptions)\n- [5.0.0](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.0.0/Google.Cloud.Diagnostics.Common.BufferOptions)\n- [4.4.0](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/4.4.0/Google.Cloud.Diagnostics.Common.BufferOptions)\n- [4.3.1](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/4.3.1/Google.Cloud.Diagnostics.Common.BufferOptions) \n\n public sealed class BufferOptions\n\nReference documentation and code samples for the Google.Cloud.Diagnostics.Common class BufferOptions.\n\nOptions that define a buffer. \n\nInheritance\n-----------\n\n[object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e BufferOptions \n\nInherited Members\n-----------------\n\n[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) \n[object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) \n[object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)\n\nNamespace\n---------\n\n[Google.Cloud.Diagnostics.Common](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common)\n\nAssembly\n--------\n\nGoogle.Cloud.Diagnostics.Common.dll\n\nProperties\n----------\n\n### BufferSizeBytes\n\n public int BufferSizeBytes { get; }\n\nThe size of the buffer in bytes, only used for [Sized](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType#Google_Cloud_Diagnostics_Common_BufferType_Sized)\n\n### BufferType\n\n public BufferType BufferType { get; }\n\nThe type of buffer to be used.\n\n### BufferWaitTime\n\n public TimeSpan BufferWaitTime { get; }\n\nThe time to wait before the buffer is flushed, only used for [Timed](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType#Google_Cloud_Diagnostics_Common_BufferType_Timed)\n\n### TimerExceptionHandler\n\n public Action\u003cException\u003e TimerExceptionHandler { get; }\n\nAn action that will be called whenever an exception is thrown during a timed flush of the buffer.\nMay be null. Only used for [Timed](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType#Google_Cloud_Diagnostics_Common_BufferType_Timed).\n\n**Remarks** \nThrowing an exception within the timer thread risks inmediately crashing the applicaiton, so we\nnever do that, even if [ExceptionHandling](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryOptions#Google_Cloud_Diagnostics_Common_RetryOptions_ExceptionHandling) has been set to\n[Propagate](/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\nan application.\nInstead, client code can specify a value for this action, that will be called when an exception is thrown\nwithin the timer thread. Client code may decide what to do in such cases.\n\nMethods\n-------\n\n### NoBuffer()\n\n public static BufferOptions NoBuffer()\n\nCreate [BufferOptions](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions) for [None](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType#Google_Cloud_Diagnostics_Common_BufferType_None)\n\n### SizedBuffer(int)\n\n public static BufferOptions SizedBuffer(int bufferSizeBytes = 65536)\n\nCreate [BufferOptions](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions) for [Sized](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType#Google_Cloud_Diagnostics_Common_BufferType_Sized)\n\n### TimedBuffer(TimeSpan?)\n\n public static BufferOptions TimedBuffer(TimeSpan? bufferWaitTime = null)\n\nCreate [BufferOptions](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions) for [Timed](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferType#Google_Cloud_Diagnostics_Common_BufferType_Timed)\n\n### WithTimerExceptionHandler(Action\\\u003cException\\\u003e)\n\n public BufferOptions WithTimerExceptionHandler(Action\u003cException\u003e handler)\n\nCreates a new [BufferOptions](/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.BufferOptions) instance which is identical to this one\nbut with the given timer exception handler."]]