{"id":464151,"date":"2025-06-23T03:02:31","date_gmt":"2025-06-23T03:02:31","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=464151"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=464151","title":{"rendered":"<span>InterpolatedStringHandler: \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u043b\u0438\u0448\u043d\u0438\u0445 \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u0432 \u043b\u043e\u0433\u0430\u0445<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 <code>ILogger.LogInformation($\"User {userId}\")<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0431\u0435\u0437\u043e\u0431\u0438\u0434\u043d\u043e, \u043d\u043e \u043d\u0430 \u0434\u0435\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440:<\/p>\n<ol>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 <code>string.Format<\/code>-like \u043b\u043e\u0433\u0438\u043a\u0443.<\/p>\n<\/li>\n<li>\n<p>\u0411\u043e\u043a\u0441\u0438\u0442 <code>userId<\/code>, <code>DateTime<\/code>, struct-\u044b \u0438 \u043f\u0440\u043e\u0447\u0435\u0435 \u0434\u043e\u0431\u0440\u043e.<\/p>\n<\/li>\n<li>\n<p>\u041b\u0438\u043d\u043a\u0443\u0435\u0442 \u0432\u0441\u0451 \u0432 <code>object[]<\/code> \u0440\u0430\u0434\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043b\u043e\u0433\u043e\u0432.<\/p>\n<\/li>\n<\/ol>\n<p>\u0410\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0446\u0435\u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u2014 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 <strong>80 \u0411<\/strong> \u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 (\u043f\u043b\u044e\u0441 \u0442\u0440\u0430\u043d\u0441\u0444\u0435\u0440\u044b \u0432 LOH, \u0435\u0441\u043b\u0438 \u0432\u044b \u043e\u0441\u043e\u0431\u043e \u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0432\u043d\u044b). <\/p>\n<blockquote>\n<p>\u0412 .NET 8 Microsoft \u0434\u0430\u0436\u0435 \u0432\u044b\u043d\u0435\u0441\u043b\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u00abhigh-performance logging\u00bb \u0438 \u0447\u0435\u0441\u0442\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u043b\u0430: \u00ab\u0414\u0430, \u043e\u0431\u044b\u0447\u043d\u044b\u0435 extension-\u043c\u0435\u0442\u043e\u0434\u044b \u043b\u043e\u0433\u043e\u0432 \u0431\u043e\u043a\u0441\u044f\u0442 \u0438 \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u044e\u0442\u00bb <\/p>\n<\/blockquote>\n<p>\u0421 \u0432\u044b\u0445\u043e\u0434\u043e\u043c C# 10 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0430\u0443\u0447\u0438\u043b\u0441\u044f \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c <code>$\"\u0441\u0442\u0440\u043e\u043a\u0430\"<\/code> \u043d\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 <code>string<\/code>, \u0430 \u0432 <strong>handler<\/strong>: \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043a\u0443\u0441\u043a\u0438 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432 \u0438 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u044b. \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u2013 <code>DefaultInterpolatedStringHandler<\/code>. \u041e\u043d \u0443\u0436\u0435 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0447\u043d\u0435\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e:<\/p>\n<ul>\n<li>\n<p>\u0441\u0440\u0430\u0437\u0443 \u0437\u043d\u0430\u0435\u0442 <code>literalLength<\/code> \u0438 <code>formattedCount<\/code>,<\/p>\n<\/li>\n<li>\n<p>\u0430\u0440\u0435\u043d\u0434\u0443\u0435\u0442 \u0431\u0443\u0444\u0435\u0440 \u0447\u0435\u0440\u0435\u0437 <code>ArrayPool&lt;char&gt;.Shared<\/code>,<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043b\u0438\u0448\u043d\u0438\u0445 \u043a\u043e\u043f\u0438\u0439. <\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u043e \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0444\u0438\u0447\u0430 \u2014 <strong>\u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 handler<\/strong>.<\/p>\n<h3>\u041f\u0438\u0448\u0435\u043c LogInterpolatedStringHandler<\/h3>\n<pre><code class=\"cs\">[InterpolatedStringHandler] public readonly struct LogInterpolatedStringHandler {     private readonly bool _enabled;     private readonly StringBuilder? _sb;      public LogInterpolatedStringHandler(         int literalLength,         int formattedCount,         ILogger logger,         LogLevel level,         out bool isEnabled)     {         _enabled = isEnabled = logger.IsEnabled(level);         _sb = _enabled ? new(literalLength) : null;     }      public void AppendLiteral(string s)     {         if (_enabled) _sb!.Append(s);     }      public void AppendFormatted&lt;T&gt;(T value)     {         if (_enabled) _sb!.Append(value);     }      public override string ToString() =&gt; _sb?.ToString() ?? string.Empty; }<\/code><\/pre>\n<p><code><strong>out bool isEnabled<\/strong><\/code> \u2014 \u0435\u0441\u043b\u0438 \u043b\u043e\u0433-\u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0435\u0449\u0435 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u0430\u0441\u0442 early-exit, \u0438 <code>Append*<\/code> \u0434\u0430\u0436\u0435 \u043d\u0435 \u0432\u044b\u0437\u043e\u0432\u0443\u0442\u0441\u044f. \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>readonly struct<\/code>: \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 + \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 heap-alloc\u043e\u0432 \u0441\u0430\u043c\u043e\u0433\u043e \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430.<\/p>\n<h3>\u0412\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0432 ILogger<\/h3>\n<pre><code class=\"cs\">public static class LoggerInterpolatedExtensions {     public static void LogInfo(this ILogger logger,         [InterpolatedStringHandlerArgument(\"\", \"level\")]         LogInterpolatedStringHandler message,         LogLevel level = LogLevel.Information)         =&gt; logger.Log(level, new EventId(), message.ToString(), null, (_, __) =&gt; _); }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e:<\/p>\n<pre><code class=\"cs\">logger.LogInfo($\"User {userId} processed {items.Count} items in {elapsedMs} ms\");<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u2014 Warning, \u0432\u0435\u0441\u044c <code>$\"\u2026\"<\/code> \u0434\u0430\u0436\u0435 \u043d\u0435 \u043d\u0430\u0447\u043d\u0435\u0442 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f.<\/p>\n<h3>\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438 <\/h3>\n<pre><code class=\"cs\">[MemoryDiagnoser] public class LogBench {     private readonly ILogger _log = new NullLogger(); \/\/ \u043f\u0443\u0441\u0442\u044b\u0448\u043a\u0430      [Benchmark(Baseline = true)]     public void Baseline_StringInterpol() =&gt;         _log.LogInformation($\"User {_id} logged at {DateTime.Now}\");      [Benchmark]     public void InterpolatedHandler() =&gt;         _log.LogInfo($\"User {_id} logged at {DateTime.Now}\"); }<\/code><\/pre>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">Method<\/p>\n<\/th>\n<th>\n<p align=\"left\">Mean (ns)<\/p>\n<\/th>\n<th>\n<p align=\"left\">Alloc (B)<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Baseline_StringInterpol<\/p>\n<\/td>\n<td>\n<p align=\"left\">82.4<\/p>\n<\/td>\n<td>\n<p align=\"left\">88<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">InterpolatedHandler<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>9.5<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>0<\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0423\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u04458, \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 0. \u041d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0435 (5 \u041a RPS, ~3 \u043b\u043e\u0433\u0430\/\u0437\u0430\u043f\u0440\u043e\u0441) \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 <strong>\u2212120 MiB<\/strong> \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043c\u0438\u043d\u0443\u0442\u0443 \u0438 \u043e\u043f\u0443\u0441\u0442\u0438\u043b\u0438 Gen2-\u0441\u0431\u043e\u0440\u043a\u0438 \u0434\u043e \u043d\u0443\u043b\u044f.<\/p>\n<h3>LoggerMessageAttribute<\/h3>\n<p>\u0422\u0430\u043a \u0436\u0435 .NET 6 \u0435\u0441\u0442\u044c source-generator <code>LoggerMessage<\/code>. \u041e\u043d \u0442\u043e\u0436\u0435 zero-alloc, \u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 partial-\u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0444\u0440\u0430\u0437\u044b;<\/p>\n<\/li>\n<li>\n<p>\u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u043b\u043e\u0433\u043e\u0432 \u2014 \u043f\u0435\u0440\u0435\u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043a\u043e\u0434;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435\u0442 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>InterpolatedStringHandler \u0434\u0430\u0435\u0442 \u0442\u0443 \u0436\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043d\u043e \u0441 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u043c <code>$\"\u2026\"<\/code>, \u0430 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043a\u043e\u0434 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u043c.<\/p>\n<h3>\u0412\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443<\/h3>\n<p>\u0412 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u043d\u0430\u0448 <code>LogInterpolatedStringHandler<\/code> \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0451 \u0432 <code>StringBuilder<\/code>, \u0438 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430. \u0414\u043b\u044f Kibana \u0438\u043b\u0438 Seq-\u0434\u0430\u0448\u0431\u043e\u0440\u0434\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u043b\u043e \u2014 \u043d\u0443\u0436\u043d\u044b <em>property values<\/em> \u0441 \u0438\u043c\u0435\u043d\u0430\u043c\u0438. \u0420\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u043e\u0439: \u0437\u0430\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u00ab\u0442\u043e\u043a\u0435\u043d\u00bb \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 <code>CallerArgumentExpression<\/code> \u0438 \u043a\u043b\u0430\u0434\u0435\u043c \u0435\u0433\u043e \u0432 \u043f\u0430\u0440\u0443 \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"cs\">public void AppendFormatted&lt;T&gt;(         T value,         [CallerArgumentExpression(\"value\")] string? name = null) {     if (!_enabled) return;     _sb!.Append($\"{{{name}:{value}}}\");   \/\/ \u0438\u043b\u0438 \u043f\u0438\u0448\u0435\u043c \u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 Dictionary }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c <code>logger.LogInfo($\"UserId {userId} processed {count}\")<\/code> \u043f\u0440\u0438\u0435\u0434\u0435\u0442 \u0432 ELK \u043a\u0430\u043a \u043f\u043e\u043b\u044f <code>UserId=42<\/code>, <code>count=17<\/code>. \u041c\u0438\u043d\u0438\u043c\u0443\u043c \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432, \u043d\u043e\u043b\u044c \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u2014 \u0430 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0430.<\/p>\n<h4>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <\/h4>\n<p>\u0425\u043e\u0442\u0438\u0442\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0447\u0438\u0441\u0435\u043b \u0438\u043b\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u043a? \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0443 \u0441 <code>IFormatProvider<\/code>:<\/p>\n<pre><code class=\"cs\">public void AppendFormatted&lt;T&gt;(         T value,         string? format,         IFormatProvider? provider = null,         [CallerArgumentExpression(\"value\")] string? name = null) {     if (!_enabled) return;     _sb!.AppendFormat(provider, $\"{{0:{format}}}\", value); }<\/code><\/pre>\n<p>\u0418\u0442\u043e\u0433\u0438 \u043a\u0432\u0430\u0440\u0442\u0430\u043b\u0430: <code>$\"{revenue,12:N0}\"<\/code> \u043f\u0440\u0438\u0434\u0443\u0442 \u0443\u0436\u0435 \u0441 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f\u043c\u0438 \u0442\u044b\u0441\u044f\u0447. \u0414\u0430\u0442\u044b: <code>$\"{timestamp:yyyy-MM-ddTHH:mm:ss.fff}\"<\/code> \u2014 \u0438 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e <code>ToString(...)<\/code> \u0432 \u043a\u043e\u0434\u0435.<\/p>\n<p>\u0414\u0430, \u043a \u0444\u043b\u043e\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e IL-\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u043d\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 &lt; 1 \u043d\u0441 \u043d\u0430 \u0432\u044b\u0437\u043e\u0432, \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u0432\u0441\u0451 \u0442\u0430\u043a \u0436\u0435 0 \u0411. Win-win.<\/p>\n<h3>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h3>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"230\" width=\"230\">\n<p align=\"left\">\n<\/th>\n<th>\n<p align=\"left\">\u041a\u0430\u043a \u043e\u0431\u043e\u0439\u0442\u0438<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"230\" width=\"230\">\n<p align=\"left\"><strong>\u0417\u0430\u0445\u0432\u0430\u0442 <\/strong><code><strong>this<\/strong><\/code> \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043d\u0435-<code>static<\/code> \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u0435\u043b\u0430\u0439\u0442\u0435 \u0445\u0435\u043d\u0434\u043b\u0435\u0440 <code>readonly struct<\/code> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u0451 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"230\" width=\"230\">\n<p align=\"left\"><strong>\u041b\u043e\u0433\u0438 \u0441 Exception<\/strong> \u2014 \u043d\u0443\u0436\u0435\u043d <code>stackTrace<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u0440\u0438\u043c\u0438\u0442\u0435 <code>Exception? ex<\/code> \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0443 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u043f\u0440\u0435\u0436\u043d\u0438\u0439 pipe<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"230\" width=\"230\">\n<p align=\"left\"><strong>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 Microsoft.Extensions.Logging<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0425\u0435\u043d\u0434\u043b\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C# 10. \u041d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 C# 9 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f <code>LangVersion=preview<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u0418\u0442\u043e\u0433<\/h3>\n<p><code>InterpolatedStringHandler<\/code> \u2014 \u044d\u0442\u043e \u043d\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440, \u0430 \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0442\u0435\u0445\u043d\u0438\u043a\u0430 \u0434\u043b\u044f <strong>zero-allocation logging<\/strong> \u0432 .NET 8+. \u0414\u0432\u0430 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u0444\u0430\u0439\u043b\u0430-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u0438 \u0432\u044b \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u0435 \u0441\u043e\u0442\u043d\u0438 \u043c\u0435\u0433\u0430\u0431\u0430\u0439\u0442 \u041e\u0417\u0423 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0440\u043e\u0434-\u043d\u043e\u0434\u0435, \u0443\u0431\u0438\u0440\u0430\u0435\u0442\u0435 stop-the-world \u043f\u0430\u0443\u0437\u044b, \u0430 \u0441\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439, \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 <code>$\"...\"<\/code>-\u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441.<\/p>\n<hr\/>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043f\u0440\u0435\u0433\u0440\u0430\u0434\u043e\u0439 \u0434\u043b\u044f \u0440\u043e\u0441\u0442\u0430, \u0432\u0430\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a \u0438\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c. \u042d\u0442\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 \u0443\u0440\u043e\u043a\u0438 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c\u0438 \u043c\u043e\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0438 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a:<\/p>\n<ul>\n<li>\n<p>24 \u0438\u044e\u043d\u044f \u0432 20:00. <a href=\"https:\/\/otus.pw\/pXP16\/\" rel=\"noopener noreferrer nofollow\"><em>\u0414\u0432\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 DDD: Rich Model vs Anemic Model <\/em><\/a><br \/>\u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u0438 \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0435\u043c\u0438\u0447\u043d\u0443\u044e \u0438\u043b\u0438 \u0431\u043e\u0433\u0430\u0442\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0433\u0438\u0431\u043a\u0438\u0445 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p>17 \u0438\u044e\u043b\u044f \u0432 20:00. <a href=\"https:\/\/otus.pw\/Hx4O\/\" rel=\"noopener noreferrer nofollow\"><em>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0432 C#: \u0417\u0430 \u0433\u0440\u0430\u043d\u044c\u044e await. \u041f\u0430\u0442\u0442\u0435\u0440\u043d\u044b, \u041e\u0448\u0438\u0431\u043a\u0438 \u0438 \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f <\/em><\/a><br \/>\u0440\u0430\u0437\u0431\u0435\u0440\u043c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<\/li>\n<\/ul>\n<p><em>\u041f\u0440\u043e\u0439\u0434\u0438\u0442\u0435 <\/em><a href=\"https:\/\/otus.pw\/BGTl\/\" rel=\"noopener noreferrer nofollow\"><em>\u0432\u0441\u0442\u0443\u043f\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0443\u0440\u0441\u0430 &#171;C# Developer. Professional&#187;<\/em><\/a><em> \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043f\u0435\u0446\u0446\u0435\u043d\u0443 \u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0437\u0430\u043f\u0438\u0441\u044f\u043c \u0443\u0440\u043e\u043a\u043e\u0432.<\/em><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/920288\/\"> https:\/\/habr.com\/ru\/articles\/920288\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 <code>ILogger.LogInformation($\"User {userId}\")<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0431\u0435\u0437\u043e\u0431\u0438\u0434\u043d\u043e, \u043d\u043e \u043d\u0430 \u0434\u0435\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440:<\/p>\n<ol>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 <code>string.Format<\/code>-like \u043b\u043e\u0433\u0438\u043a\u0443.<\/p>\n<\/li>\n<li>\n<p>\u0411\u043e\u043a\u0441\u0438\u0442 <code>userId<\/code>, <code>DateTime<\/code>, struct-\u044b \u0438 \u043f\u0440\u043e\u0447\u0435\u0435 \u0434\u043e\u0431\u0440\u043e.<\/p>\n<\/li>\n<li>\n<p>\u041b\u0438\u043d\u043a\u0443\u0435\u0442 \u0432\u0441\u0451 \u0432 <code>object[]<\/code> \u0440\u0430\u0434\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043b\u043e\u0433\u043e\u0432.<\/p>\n<\/li>\n<\/ol>\n<p>\u0410\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u0430\u044f \u0446\u0435\u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441\u0430 \u2014 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 <strong>80 \u0411<\/strong> \u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 (\u043f\u043b\u044e\u0441 \u0442\u0440\u0430\u043d\u0441\u0444\u0435\u0440\u044b \u0432 LOH, \u0435\u0441\u043b\u0438 \u0432\u044b \u043e\u0441\u043e\u0431\u043e \u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0432\u043d\u044b). <\/p>\n<blockquote>\n<p>\u0412 .NET 8 Microsoft \u0434\u0430\u0436\u0435 \u0432\u044b\u043d\u0435\u0441\u043b\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u00abhigh-performance logging\u00bb \u0438 \u0447\u0435\u0441\u0442\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u043b\u0430: \u00ab\u0414\u0430, \u043e\u0431\u044b\u0447\u043d\u044b\u0435 extension-\u043c\u0435\u0442\u043e\u0434\u044b \u043b\u043e\u0433\u043e\u0432 \u0431\u043e\u043a\u0441\u044f\u0442 \u0438 \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u0443\u044e\u0442\u00bb <\/p>\n<\/blockquote>\n<p>\u0421 \u0432\u044b\u0445\u043e\u0434\u043e\u043c C# 10 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0430\u0443\u0447\u0438\u043b\u0441\u044f \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c <code>$\"\u0441\u0442\u0440\u043e\u043a\u0430\"<\/code> \u043d\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 <code>string<\/code>, \u0430 \u0432 <strong>handler<\/strong>: \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043a\u0443\u0441\u043a\u0438 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u0432 \u0438 \u043f\u043b\u0435\u0439\u0441\u0445\u043e\u043b\u0434\u0435\u0440\u044b. \u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u2013 <code>DefaultInterpolatedStringHandler<\/code>. \u041e\u043d \u0443\u0436\u0435 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0447\u043d\u0435\u0435, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e:<\/p>\n<ul>\n<li>\n<p>\u0441\u0440\u0430\u0437\u0443 \u0437\u043d\u0430\u0435\u0442 <code>literalLength<\/code> \u0438 <code>formattedCount<\/code>,<\/p>\n<\/li>\n<li>\n<p>\u0430\u0440\u0435\u043d\u0434\u0443\u0435\u0442 \u0431\u0443\u0444\u0435\u0440 \u0447\u0435\u0440\u0435\u0437 <code>ArrayPool&lt;char&gt;.Shared<\/code>,<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043b\u0438\u0448\u043d\u0438\u0445 \u043a\u043e\u043f\u0438\u0439. <\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u043e \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0444\u0438\u0447\u0430 \u2014 <strong>\u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 handler<\/strong>.<\/p>\n<h3>\u041f\u0438\u0448\u0435\u043c LogInterpolatedStringHandler<\/h3>\n<pre><code class=\"cs\">[InterpolatedStringHandler] public readonly struct LogInterpolatedStringHandler {     private readonly bool _enabled;     private readonly StringBuilder? _sb;      public LogInterpolatedStringHandler(         int literalLength,         int formattedCount,         ILogger logger,         LogLevel level,         out bool isEnabled)     {         _enabled = isEnabled = logger.IsEnabled(level);         _sb = _enabled ? new(literalLength) : null;     }      public void AppendLiteral(string s)     {         if (_enabled) _sb!.Append(s);     }      public void AppendFormatted&lt;T&gt;(T value)     {         if (_enabled) _sb!.Append(value);     }      public override string ToString() =&gt; _sb?.ToString() ?? string.Empty; }<\/code><\/pre>\n<p><code><strong>out bool isEnabled<\/strong><\/code> \u2014 \u0435\u0441\u043b\u0438 \u043b\u043e\u0433-\u0443\u0440\u043e\u0432\u0435\u043d\u044c \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0435\u0449\u0435 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0440\u0430\u0437\u0431\u043e\u0440\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u0434\u0430\u0441\u0442 early-exit, \u0438 <code>Append*<\/code> \u0434\u0430\u0436\u0435 \u043d\u0435 \u0432\u044b\u0437\u043e\u0432\u0443\u0442\u0441\u044f. \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>readonly struct<\/code>: \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 + \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 heap-alloc\u043e\u0432 \u0441\u0430\u043c\u043e\u0433\u043e \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0430.<\/p>\n<h3>\u0412\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0432 ILogger<\/h3>\n<pre><code class=\"cs\">public static class LoggerInterpolatedExtensions {     public static void LogInfo(this ILogger logger,         [InterpolatedStringHandlerArgument(\"\", \"level\")]         LogInterpolatedStringHandler message,         LogLevel level = LogLevel.Information)         =&gt; logger.Log(level, new EventId(), message.ToString(), null, (_, __) =&gt; _); }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e:<\/p>\n<pre><code class=\"cs\">logger.LogInfo($\"User {userId} processed {items.Count} items in {elapsedMs} ms\");<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u2014 Warning, \u0432\u0435\u0441\u044c <code>$\"\u2026\"<\/code> \u0434\u0430\u0436\u0435 \u043d\u0435 \u043d\u0430\u0447\u043d\u0435\u0442 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f.<\/p>\n<h3>\u0411\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0438 <\/h3>\n<pre><code class=\"cs\">[MemoryDiagnoser] public class LogBench {     private readonly ILogger _log = new NullLogger(); \/\/ \u043f\u0443\u0441\u0442\u044b\u0448\u043a\u0430      [Benchmark(Baseline = true)]     public void Baseline_StringInterpol() =&gt;         _log.LogInformation($\"User {_id} logged at {DateTime.Now}\");      [Benchmark]     public void InterpolatedHandler() =&gt;         _log.LogInfo($\"User {_id} logged at {DateTime.Now}\"); }<\/code><\/pre>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">Method<\/p>\n<\/th>\n<th>\n<p align=\"left\">Mean (ns)<\/p>\n<\/th>\n<th>\n<p align=\"left\">Alloc (B)<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">Baseline_StringInterpol<\/p>\n<\/td>\n<td>\n<p align=\"left\">82.4<\/p>\n<\/td>\n<td>\n<p align=\"left\">88<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">InterpolatedHandler<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>9.5<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>0<\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0423\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u0435 \u04458, \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0438 0. \u041d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u0435 (5 \u041a RPS, ~3 \u043b\u043e\u0433\u0430\/\u0437\u0430\u043f\u0440\u043e\u0441) \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 <strong>\u2212120 MiB<\/strong> \u0430\u043b\u043b\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043c\u0438\u043d\u0443\u0442\u0443 \u0438 \u043e\u043f\u0443\u0441\u0442\u0438\u043b\u0438 Gen2-\u0441\u0431\u043e\u0440\u043a\u0438 \u0434\u043e \u043d\u0443\u043b\u044f.<\/p>\n<h3>LoggerMessageAttribute<\/h3>\n<p>\u0422\u0430\u043a \u0436\u0435 .NET 6 \u0435\u0441\u0442\u044c source-generator <code>LoggerMessage<\/code>. \u041e\u043d \u0442\u043e\u0436\u0435 zero-alloc, \u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 partial-\u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0444\u0440\u0430\u0437\u044b;<\/p>\n<\/li>\n<li>\n<p>\u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u043b\u043e\u0433\u043e\u0432 \u2014 \u043f\u0435\u0440\u0435\u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u043a\u043e\u0434;<\/p>\n<\/li>\n<li>\n<p>\u043d\u0435\u0442 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u0432 \u0440\u0430\u043d\u0442\u0430\u0439\u043c\u0435.<\/p>\n<\/li>\n<\/ul>\n<p>InterpolatedStringHandler \u0434\u0430\u0435\u0442 \u0442\u0443 \u0436\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c, \u043d\u043e \u0441 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u043c <code>$\"\u2026\"<\/code>, \u0430 \u0440\u0430\u0431\u043e\u0447\u0438\u0439 \u043a\u043e\u0434 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u043c.<\/p>\n<h3>\u0412\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443<\/h3>\n<p>\u0412 \u0431\u0430\u0437\u043e\u0432\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u043d\u0430\u0448 <code>LogInterpolatedStringHandler<\/code> \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0451 \u0432 <code>StringBuilder<\/code>, \u0438 \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430. \u0414\u043b\u044f Kibana \u0438\u043b\u0438 Seq-\u0434\u0430\u0448\u0431\u043e\u0440\u0434\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u043b\u043e \u2014 \u043d\u0443\u0436\u043d\u044b <em>property values<\/em> \u0441 \u0438\u043c\u0435\u043d\u0430\u043c\u0438. \u0420\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u043e\u0439: \u0437\u0430\u0431\u0438\u0440\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u00ab\u0442\u043e\u043a\u0435\u043d\u00bb \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 <code>CallerArgumentExpression<\/code> \u0438 \u043a\u043b\u0430\u0434\u0435\u043c \u0435\u0433\u043e \u0432 \u043f\u0430\u0440\u0443 \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"cs\">public void AppendFormatted&lt;T&gt;(         T value,         [CallerArgumentExpression(\"value\")] string? name = null) {     if (!_enabled) return;     _sb!.Append($\"{{{name}:{value}}}\");   \/\/ \u0438\u043b\u0438 \u043f\u0438\u0448\u0435\u043c \u0432\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0439 Dictionary }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c <code>logger.LogInfo($\"UserId {userId} processed {count}\")<\/code> \u043f\u0440\u0438\u0435\u0434\u0435\u0442 \u0432 ELK \u043a\u0430\u043a \u043f\u043e\u043b\u044f <code>UserId=42<\/code>, <code>count=17<\/code>. \u041c\u0438\u043d\u0438\u043c\u0443\u043c \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432, \u043d\u043e\u043b\u044c \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u2014 \u0430 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0430.<\/p>\n<h4>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0435 \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <\/h4>\n<p>\u0425\u043e\u0442\u0438\u0442\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0447\u0438\u0441\u0435\u043b \u0438\u043b\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u043a? \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0443 \u0441 <code>IFormatProvider<\/code>:<\/p>\n<pre><code class=\"cs\">public void AppendFormatted&lt;T&gt;(         T value,         string? format,         IFormatProvider? provider = null,         [CallerArgumentExpression(\"value\")] string? name = null) {     if (!_enabled) return;     _sb!.AppendFormat(provider, $\"{{0:{format}}}\", value); }<\/code><\/pre>\n<p>\u0418\u0442\u043e\u0433\u0438 \u043a\u0432\u0430\u0440\u0442\u0430\u043b\u0430: <code>$\"{revenue,12:N0}\"<\/code> \u043f\u0440\u0438\u0434\u0443\u0442 \u0443\u0436\u0435 \u0441 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f\u043c\u0438 \u0442\u044b\u0441\u044f\u0447. \u0414\u0430\u0442\u044b: <code>$\"{timestamp:yyyy-MM-ddTHH:mm:ss.fff}\"<\/code> \u2014 \u0438 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e <code>ToString(...)<\/code> \u0432 \u043a\u043e\u0434\u0435.<\/p>\n<p>\u0414\u0430, \u043a \u0444\u043b\u043e\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e IL-\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u043d\u043e \u043f\u0440\u043e\u0444\u0438\u043b\u0438\u0440\u043e\u0432\u0449\u0438\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 &lt; 1 \u043d\u0441 \u043d\u0430 \u0432\u044b\u0437\u043e\u0432, \u0430\u043b\u043b\u043e\u043a\u0430\u0446\u0438\u0439 \u0432\u0441\u0451 \u0442\u0430\u043a \u0436\u0435 0 \u0411. Win-win.<\/p>\n<h3>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h3>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th data-colwidth=\"230\" width=\"230\">\n<p align=\"left\">\n<\/th>\n<th>\n<p align=\"left\">\u041a\u0430\u043a \u043e\u0431\u043e\u0439\u0442\u0438<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td data-colwidth=\"230\" width=\"230\">\n<p align=\"left\"><strong>\u0417\u0430\u0445\u0432\u0430\u0442 <\/strong><code><strong>this<\/strong><\/code> \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043d\u0435-<code>static<\/code> \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0414\u0435\u043b\u0430\u0439\u0442\u0435 \u0445\u0435\u043d\u0434\u043b\u0435\u0440 <code>readonly struct<\/code> \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0441\u0451 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"230\" width=\"230\">\n<p align=\"left\"><strong>\u041b\u043e\u0433\u0438 \u0441 Exception<\/strong> \u2014 \u043d\u0443\u0436\u0435\u043d <code>stackTrace<\/code><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u0440\u0438\u043c\u0438\u0442\u0435 <code>Exception? ex<\/code> \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0443 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u043f\u0440\u0435\u0436\u043d\u0438\u0439 pipe<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"230\" width=\"230\">\n<p align=\"left\"><strong>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 Microsoft.Extensions.Logging<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0425\u0435\u043d\u0434\u043b\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 C# 10. \u041d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 C# 9 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f <code>LangVersion=preview<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>\u0418\u0442\u043e\u0433<\/h3>\n<p><code>InterpolatedStringHandler<\/code> \u2014 \u044d\u0442\u043e \u043d\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0430\u0445\u0430\u0440, \u0430 \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u0442\u0435\u0445\u043d\u0438\u043a\u0430 \u0434\u043b\u044f <strong>zero-allocation logging<\/strong> \u0432 .NET 8+. \u0414\u0432\u0430 \u043a\u043e\u0440\u043e\u0442\u043a\u0438\u0445 \u0444\u0430\u0439\u043b\u0430-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f, \u0438 \u0432\u044b \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u0435 \u0441\u043e\u0442\u043d\u0438 \u043c\u0435\u0433\u0430\u0431\u0430\u0439\u0442 \u041e\u0417\u0423 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0440\u043e\u0434-\u043d\u043e\u0434\u0435, \u0443\u0431\u0438\u0440\u0430\u0435\u0442\u0435 stop-the-world \u043f\u0430\u0443\u0437\u044b, \u0430 \u0441\u0430\u043c\u043e\u0435 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439, \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0439 <code>$\"...\"<\/code>-\u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441.<\/p>\n<hr\/>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u044b\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u0442\u0430\u043d\u043e\u0432\u044f\u0442\u0441\u044f \u043f\u0440\u0435\u0433\u0440\u0430\u0434\u043e\u0439 \u0434\u043b\u044f \u0440\u043e\u0441\u0442\u0430, \u0432\u0430\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a \u0438\u0445 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0440\u0435\u0448\u0430\u0442\u044c. \u042d\u0442\u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0435 \u0443\u0440\u043e\u043a\u0438 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0432\u0430\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c\u0438 \u043c\u043e\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0438 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u0445 \u043e\u0448\u0438\u0431\u043e\u043a:<\/p>\n<ul>\n<li>\n<p>24 \u0438\u044e\u043d\u044f \u0432 20:00. <a href=\"https:\/\/otus.pw\/pXP16\/\" rel=\"noopener noreferrer nofollow\"><em>\u0414\u0432\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 DDD: Rich Model vs Anemic Model <\/em><\/a><br \/>\u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u043a\u043e\u0433\u0434\u0430 \u0438 \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0435\u043c\u0438\u0447\u043d\u0443\u044e \u0438\u043b\u0438 \u0431\u043e\u0433\u0430\u0442\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0433\u0438\u0431\u043a\u0438\u0445 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c.<\/p>\n<\/li>\n<li>\n<p>17 \u0438\u044e\u043b\u044f \u0432 20:00. <a href=\"https:\/\/otus.pw\/Hx4O\/\" rel=\"noopener noreferrer nofollow\"><em>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0441\u0442\u044c \u0432 C#: \u0417\u0430 \u0433\u0440\u0430\u043d\u044c\u044e await. \u041f\u0430\u0442\u0442\u0435\u0440\u043d\u044b, \u041e\u0448\u0438\u0431\u043a\u0438 \u0438 \u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f <\/em><\/a><br \/>\u0440\u0430\u0437\u0431\u0435\u0440\u043c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a \u0438 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430.<\/p>\n<\/li>\n<\/ul>\n<p><em>\u041f\u0440\u043e\u0439\u0434\u0438\u0442\u0435 <\/em><a href=\"https:\/\/otus.pw\/BGTl\/\" rel=\"noopener noreferrer nofollow\"><em>\u0432\u0441\u0442\u0443\u043f\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u0443\u0440\u0441\u0430 &#171;C# Developer. Professional&#187;<\/em><\/a><em> \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u0441\u043f\u0435\u0446\u0446\u0435\u043d\u0443 \u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0437\u0430\u043f\u0438\u0441\u044f\u043c \u0443\u0440\u043e\u043a\u043e\u0432.<\/em><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/920288\/\"> https:\/\/habr.com\/ru\/articles\/920288\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-464151","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=464151"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/464151\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=464151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=464151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=464151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}