@@ -60,7 +60,6 @@ internal LogRecord(
6060 this . ILoggerData = new ( )
6161 {
6262 TraceState = activity ? . TraceStateString ,
63- CategoryName = categoryName ,
6463 FormattedMessage = formattedMessage ,
6564 EventId = eventId ,
6665 Exception = exception ,
@@ -79,6 +78,8 @@ internal LogRecord(
7978
8079 this . AttributeData = stateValues ;
8180 }
81+
82+ this . Logger = InstrumentationScopeLogger . GetInstrumentationScopeLoggerForName ( categoryName ) ;
8283 }
8384
8485 internal enum LogRecordSource
@@ -153,16 +154,31 @@ public string? TraceState
153154 set => this . ILoggerData . TraceState = value ;
154155 }
155156
157+ #if EXPOSE_EXPERIMENTAL_FEATURES
156158 /// <summary>
157159 /// Gets or sets the log category name.
158160 /// </summary>
159161 /// <remarks>
160- /// Note: <see cref="CategoryName"/> is only set when emitting logs through <see cref="ILogger"/>.
162+ /// Note: <see cref="CategoryName"/> is an alias for the <see
163+ /// cref="Logger.Name"/> accessed via the <see cref="Logger"/> property.
164+ /// Setting a new value for <see cref="CategoryName"/> will result in a new
165+ /// <see cref="Logger"/> being set.
161166 /// </remarks>
167+ #else
168+ /// <summary>
169+ /// Gets or sets the log category name.
170+ /// </summary>
171+ #endif
162172 public string ? CategoryName
163173 {
164- get => this . ILoggerData . CategoryName ;
165- set => this . ILoggerData . CategoryName = value ;
174+ get => this . Logger . Name ;
175+ set
176+ {
177+ if ( this . Logger . Name != value )
178+ {
179+ this . Logger = InstrumentationScopeLogger . GetInstrumentationScopeLoggerForName ( value ) ;
180+ }
181+ }
166182 }
167183
168184 /// <summary>
@@ -379,18 +395,26 @@ public Exception? Exception
379395
380396#if EXPOSE_EXPERIMENTAL_FEATURES
381397 /// <summary>
382- /// Gets the <see cref="Logs.Logger"/> which emitted the <see cref="LogRecord"/>.
398+ /// Gets the <see cref="Logs.Logger"/> associated with the <see
399+ /// cref="LogRecord"/>.
383400 /// </summary>
384- /// <remarks><inheritdoc cref="Sdk.CreateLoggerProviderBuilder" path="/remarks"/></remarks>
401+ /// <remarks>
402+ /// <para><inheritdoc cref="Sdk.CreateLoggerProviderBuilder" path="/remarks"/></para>
403+ /// Note: When using the Log Bridge API (for example <see
404+ /// cref="Logger.EmitLog(in LogRecordData)"/>) <see cref="Logger"/> is
405+ /// typically the <see cref="Logs.Logger"/> which emitted the <see
406+ /// cref="LogRecord"/> however the value may be different if <see
407+ /// cref="CategoryName"/> is modified.</remarks>
385408#if NET8_0_OR_GREATER
386409 [ Experimental ( DiagnosticDefinitions . LogsBridgeExperimentalApi , UrlFormat = DiagnosticDefinitions . ExperimentalApiUrlFormat ) ]
387410#endif
388- public Logger ? Logger { get ; internal set ; }
411+ public Logger Logger { get ; internal set ; } = InstrumentationScopeLogger . Default ;
389412#else
390413 /// <summary>
391- /// Gets or sets the <see cref="Logs.Logger"/> which emitted the <see cref="LogRecord"/>.
414+ /// Gets or sets the <see cref="Logs.Logger"/> associated with the <see
415+ /// cref="LogRecord"/>.
392416 /// </summary>
393- internal Logger ? Logger { get ; set ; }
417+ internal Logger Logger { get ; set ; } = InstrumentationScopeLogger . Default ;
394418#endif
395419
396420 /// <summary>
@@ -523,7 +547,6 @@ private void BufferLogScopes()
523547 internal struct LogRecordILoggerData
524548 {
525549 public string ? TraceState ;
526- public string ? CategoryName ;
527550 public EventId EventId ;
528551 public string ? FormattedMessage ;
529552 public Exception ? Exception ;
@@ -536,7 +559,6 @@ public LogRecordILoggerData Copy()
536559 var copy = new LogRecordILoggerData
537560 {
538561 TraceState = this . TraceState ,
539- CategoryName = this . CategoryName ,
540562 EventId = this . EventId ,
541563 FormattedMessage = this . FormattedMessage ,
542564 Exception = this . Exception ,
0 commit comments