perf(logging): use AsSpan for substring in LogCurl to reduce allocations
- Replaced `.Substring(0, maxLength)` with `AsSpan(0, maxLength)` and `string.Concat`. - Improves performance by avoiding temporary string allocations when truncating cURL output. - Maintains existing logging behavior with truncated cURL strings.
This commit is contained in:
parent
e9a7ef910f
commit
66cfe0525c
@ -15,10 +15,10 @@ public static class LogExtensions
|
|||||||
int maxLength = 1000,
|
int maxLength = 1000,
|
||||||
LogLevel logLevel = LogLevel.Information)
|
LogLevel logLevel = LogLevel.Information)
|
||||||
{
|
{
|
||||||
var curl = client.GenerateCurlInString(
|
var curl = string.Concat(client.GenerateCurlInString(
|
||||||
request,
|
request,
|
||||||
config
|
config
|
||||||
).Substring(0, maxLength) + "...[truncated]";
|
).AsSpan(0, maxLength), "...[truncated]");
|
||||||
logger?.Log(logLevel, "{curl}", curl);
|
logger?.Log(logLevel, "{curl}", curl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,13 +33,13 @@ public static class LogExtensions
|
|||||||
int maxLength = 1000,
|
int maxLength = 1000,
|
||||||
LogLevel logLevel = LogLevel.Information)
|
LogLevel logLevel = LogLevel.Information)
|
||||||
{
|
{
|
||||||
var curl = client.GenerateCurlInString(
|
var curl = string.Concat(client.GenerateCurlInString(
|
||||||
method,
|
method,
|
||||||
uri,
|
uri,
|
||||||
headers,
|
headers,
|
||||||
content,
|
content,
|
||||||
config
|
config
|
||||||
).Substring(0, maxLength) + "...[truncated]";
|
).AsSpan(0, maxLength), "...[truncated]");
|
||||||
logger?.Log(logLevel, "{curl}", curl);
|
logger?.Log(logLevel, "{curl}", curl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,13 +54,13 @@ public static class LogExtensions
|
|||||||
int maxLength = 1000,
|
int maxLength = 1000,
|
||||||
LogLevel logLevel = LogLevel.Information)
|
LogLevel logLevel = LogLevel.Information)
|
||||||
{
|
{
|
||||||
var curl = client.GenerateCurlInString(
|
var curl = string.Concat(client.GenerateCurlInString(
|
||||||
method,
|
method,
|
||||||
uri,
|
uri,
|
||||||
headers,
|
headers,
|
||||||
content,
|
content,
|
||||||
config
|
config
|
||||||
).Substring(0, maxLength) + "...[truncated]";
|
).AsSpan(0, maxLength), "...[truncated]");
|
||||||
logger?.Log(logLevel, "{curl}", curl);
|
logger?.Log(logLevel, "{curl}", curl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user