File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
src/NLog/LayoutRenderers/Wrappers Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,11 @@ protected override void InitializeLayoutRenderer()
7070
7171 if ( Inner is SimpleLayout innerLayout && WhenEmpty is SimpleLayout whenEmptyLayout )
7272 {
73- if ( ( innerLayout . IsFixedText || innerLayout . IsSimpleStringText ) && ( whenEmptyLayout . IsFixedText || whenEmptyLayout . IsSimpleStringText ) )
73+ if ( innerLayout . IsFixedText )
74+ {
75+ _stringValueRenderer = ResolveFixedWhenEmpty ( innerLayout , whenEmptyLayout ) ;
76+ }
77+ else if ( innerLayout . IsSimpleStringText && ( whenEmptyLayout . IsFixedText || whenEmptyLayout . IsSimpleStringText ) )
7478 {
7579 _stringValueRenderer = ( logEvent ) =>
7680 {
@@ -81,6 +85,24 @@ protected override void InitializeLayoutRenderer()
8185 }
8286 }
8387
88+ private static Func < LogEventInfo , string > ? ResolveFixedWhenEmpty ( SimpleLayout innerLayout , SimpleLayout whenEmptyLayout )
89+ {
90+ if ( ! string . IsNullOrEmpty ( innerLayout . FixedText ) )
91+ {
92+ return ( logEvent ) => innerLayout . FixedText ?? string . Empty ;
93+ }
94+ else if ( whenEmptyLayout . IsFixedText )
95+ {
96+ return ( logEvent ) => whenEmptyLayout . FixedText ?? string . Empty ;
97+ }
98+ else if ( whenEmptyLayout . IsSimpleStringText )
99+ {
100+ return ( logEvent ) => whenEmptyLayout . Render ( logEvent ) ;
101+ }
102+
103+ return null ;
104+ }
105+
84106 /// <inheritdoc/>
85107 protected override void RenderInnerAndTransform ( LogEventInfo logEvent , StringBuilder builder , int orgLength )
86108 {
You can’t perform that action at this time.
0 commit comments