Visitar URL original
Replacing ProcessInfoLayoutRenderer with ProcessStartLayoutRenderer by snakefoot · Pull Request #6231 · NLog/NLog · GitHub
Skip to content

Replacing ProcessInfoLayoutRenderer with ProcessStartLayoutRenderer - #6231

Merged
snakefoot merged 1 commit into
NLog:devfrom
snakefoot:ProcessInfoTrim
Aug 11, 2026
Merged

snakefoot merged 1 commit into
NLog:devfrom
snakefoot:ProcessInfoTrim

Conversation

@snakefoot

@snakefoot snakefoot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor
  • Wait for NLog v6.2

NET11 reduces the AOT-filesize when not using exotic features from the Process-object.

Changed ${processinfo} to only support Id + Name + WorkingSet, and everything else are either hardcoded values or compatibility values.

Instead introduced ${processstart} with the following options:

  • Format
  • UniversalTime
  • Culture

${processstart} outputs the same value during the entire AppDomain-lifetime, which allows NLog to convert into literal for optimal performance.

And there is also the existing ${processid} + ${processname} + ${processtime} + ${gc}. And have now introduced support for ${gc:workingset}

This PR with NET10 (Guess NET11 will be better)
ProcessPath: 'C:\projects\nlog\Tests\TestTrimPublish\bin\release\net10.0\win-X64\publish\TestTrimPublish.exe' with FileSize: 5349376

NLog v6.1.4
ProcessPath: 'C:\projects\nlog\Tests\TestTrimPublish\bin\release\net10.0\win-X64\publish\TestTrimPublish.exe' with FileSize: 5384192

@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds the ${processstart} renderer with configurable time formatting, registers its alias, and tests it. The legacy ${processinfo} renderer and enum are marked obsolete and refactored to use IAppEnvironment instead of reflection.

Changes

Process rendering

Layer / File(s) Summary
Process info compatibility refactor
src/NLog/LayoutRenderers/ProcessInfoProperty.cs, src/NLog/LayoutRenderers/ProcessInfoLayoutRenderer.cs, tests/NLog.UnitTests/LayoutRenderers/ProcessInfoLayoutRendererTests.cs
The legacy process info API is marked obsolete, gains UTC start-time metadata, uses IAppEnvironment-based values, and is covered by property rendering tests.
Process start renderer implementation
src/NLog/LayoutRenderers/ProcessStartLayoutRenderer.cs, tests/NLog.UnitTests/LayoutRenderers/ProcessStartLayoutRendererTests.cs
Adds configurable local/UTC formatting and raw-value support for LogEventInfo.ZeroDate, with invariant-culture coverage.
Process start layout registration
src/NLog/Config/AssemblyExtensionTypes.cs
Registers ProcessStartLayoutRenderer under the processstart alias.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant LayoutConfiguration
  participant ProcessStartLayoutRenderer
  participant LogEventInfo
  LayoutConfiguration->>ProcessStartLayoutRenderer: configure Format, Culture, and UniversalTime
  ProcessStartLayoutRenderer->>LogEventInfo: read ZeroDate
  LogEventInfo-->>ProcessStartLayoutRenderer: process start timestamp
  ProcessStartLayoutRenderer-->>LayoutConfiguration: formatted timestamp or raw DateTime
Loading

Poem

A rabbit hops through timestamps bright,
UTC by day and local by night.
Process info sheds its reflective shell,
While ${processstart} rings the bell.
Neat little values, rendered just right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description directly explains the ProcessInfoLayoutRenderer changes and the new ProcessStartLayoutRenderer options and behavior.
Title check ✅ Passed The title clearly and concisely describes the main change: replacing ProcessInfoLayoutRenderer with ProcessStartLayoutRenderer.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
tests/NLog.UnitTests/LayoutRenderers/ProcessStartLayoutRendererTests.cs (1)

41-48: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add test coverage for custom Format and IRawValue.

The single test covers the UTC path but misses:

  • Custom Format (e.g., ${processstart:yyyy-MM-dd}) to verify [DefaultParameter] wiring.
  • IRawValue.TryGetRawValue to verify the raw DateTime is returned correctly for structured logging.
  • Default UniversalTime=false (local time) — can be tested by computing expected from LogEventInfo.ZeroDate.ToLocalTime().
♻️ Suggested additional tests
         [Fact]
         public void RenderProcessStartLayoutRenderer()
         {
             Layout layout = "${processstart:Culture=InvariantCulture:UniversalTime=true}";
             var timestamp = LogEventInfo.ZeroDate;
             var expected = timestamp.ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
             AssertLayoutRendererOutput(layout, LogEventInfo.CreateNullEvent(), expected);
         }
+
+        [Fact]
+        public void RenderProcessStartCustomFormatTest()
+        {
+            Layout layout = "${processstart:format=yyyy-MM-dd:Culture=InvariantCulture:UniversalTime=true}";
+            var expected = LogEventInfo.ZeroDate.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
+            AssertLayoutRendererOutput(layout, LogEventInfo.CreateNullEvent(), expected);
+        }
+
+        [Fact]
+        public void RenderProcessStartLocalTimeTest()
+        {
+            Layout layout = "${processstart:Culture=InvariantCulture}";
+            var expected = LogEventInfo.ZeroDate.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
+            AssertLayoutRendererOutput(layout, LogEventInfo.CreateNullEvent(), expected);
+        }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/NLog.UnitTests/LayoutRenderers/ProcessStartLayoutRendererTests.cs`
around lines 41 - 48, Add test coverage alongside
RenderProcessStartLayoutRenderer for the custom Format parameter (for example,
yyyy-MM-dd), IRawValue.TryGetRawValue returning the underlying DateTime, and the
default UniversalTime=false behavior using LogEventInfo.ZeroDate.ToLocalTime().
tests/NLog.UnitTests/LayoutRenderers/ProcessInfoLayoutRendererTests.cs (1)

44-55: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider strengthening assertions beyond Assert.NotEmpty.

The test verifies that every property produces non-empty output, which is a useful smoke test. However, it doesn't validate correctness of any specific value (e.g., StartTime producing a valid date, Id matching the current process ID). Adding targeted assertions for key properties like Id, StartTime, and StartTimeUtc would increase confidence in the refactored implementation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/NLog.UnitTests/LayoutRenderers/ProcessInfoLayoutRendererTests.cs`
around lines 44 - 55, Strengthen ProcessInfoPropertyTest with targeted
assertions for key properties instead of relying only on Assert.NotEmpty: verify
Id matches the current process ID and assert StartTime and StartTimeUtc render
parseable, valid date-time values. Keep the existing loop as a smoke test for
the remaining ProcessInfoProperty values.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/NLog.UnitTests/LayoutRenderers/ProcessInfoLayoutRendererTests.cs`:
- Around line 44-55: Strengthen ProcessInfoPropertyTest with targeted assertions
for key properties instead of relying only on Assert.NotEmpty: verify Id matches
the current process ID and assert StartTime and StartTimeUtc render parseable,
valid date-time values. Keep the existing loop as a smoke test for the remaining
ProcessInfoProperty values.

In `@tests/NLog.UnitTests/LayoutRenderers/ProcessStartLayoutRendererTests.cs`:
- Around line 41-48: Add test coverage alongside
RenderProcessStartLayoutRenderer for the custom Format parameter (for example,
yyyy-MM-dd), IRawValue.TryGetRawValue returning the underlying DateTime, and the
default UniversalTime=false behavior using LogEventInfo.ZeroDate.ToLocalTime().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 62e8918b-e5c0-4a45-a223-56c6b64cca97

📥 Commits

Reviewing files that changed from the base of the PR and between a342b92 and 61fb5b2.

📒 Files selected for processing (6)
  • src/NLog/Config/AssemblyExtensionTypes.cs
  • src/NLog/LayoutRenderers/ProcessInfoLayoutRenderer.cs
  • src/NLog/LayoutRenderers/ProcessInfoProperty.cs
  • src/NLog/LayoutRenderers/ProcessStartLayoutRenderer.cs
  • tests/NLog.UnitTests/LayoutRenderers/ProcessInfoLayoutRendererTests.cs
  • tests/NLog.UnitTests/LayoutRenderers/ProcessStartLayoutRendererTests.cs

@snakefoot
snakefoot force-pushed the ProcessInfoTrim branch 4 times, most recently from 4940c1a to a93b27b Compare July 11, 2026 09:56

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/NLog/LayoutRenderers/ProcessInfoLayoutRenderer.cs (1)

137-139: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

MachineName now renders empty — consider Environment.MachineName.

This branch emits an empty string (the test even skips MachineName for this reason), a behavior change from the previous real value. Environment.MachineName is AOT-safe and would preserve the prior output.

♻️ Proposed change
                 case ProcessInfoProperty.MachineName:
-                    builder.Append("");
+                    builder.Append(Environment.MachineName);
                     break;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/NLog/LayoutRenderers/ProcessInfoLayoutRenderer.cs` around lines 137 -
139, Update the ProcessInfoProperty.MachineName branch in
ProcessInfoLayoutRenderer to append Environment.MachineName instead of an empty
string, preserving the prior real machine-name output and allowing the
corresponding test to cover this property.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/NLog/LayoutRenderers/ProcessInfoLayoutRenderer.cs`:
- Around line 137-139: Update the ProcessInfoProperty.MachineName branch in
ProcessInfoLayoutRenderer to append Environment.MachineName instead of an empty
string, preserving the prior real machine-name output and allowing the
corresponding test to cover this property.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2d9d54e4-bd47-4c84-99a2-0410e9da4653

📥 Commits

Reviewing files that changed from the base of the PR and between 4940c1a and a93b27b.

📒 Files selected for processing (6)
  • src/NLog/Config/AssemblyExtensionTypes.cs
  • src/NLog/LayoutRenderers/ProcessInfoLayoutRenderer.cs
  • src/NLog/LayoutRenderers/ProcessInfoProperty.cs
  • src/NLog/LayoutRenderers/ProcessStartLayoutRenderer.cs
  • tests/NLog.UnitTests/LayoutRenderers/ProcessInfoLayoutRendererTests.cs
  • tests/NLog.UnitTests/LayoutRenderers/ProcessStartLayoutRendererTests.cs
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/NLog.UnitTests/LayoutRenderers/ProcessStartLayoutRendererTests.cs
  • src/NLog/LayoutRenderers/ProcessStartLayoutRenderer.cs
  • src/NLog/Config/AssemblyExtensionTypes.cs
  • src/NLog/LayoutRenderers/ProcessInfoProperty.cs

@snakefoot
snakefoot force-pushed the ProcessInfoTrim branch 2 times, most recently from 42e1e7a to d964ad1 Compare July 11, 2026 10:13
@snakefoot snakefoot added this to the 6.2 milestone Jul 15, 2026
@sonarqubecloud

sonarqubecloud Bot commented Aug 8, 2026

Copy link
Copy Markdown

@snakefoot
snakefoot merged commit 5e483c1 into NLog:dev Aug 11, 2026
5 of 6 checks passed
@snakefoot snakefoot added needs documentation on wiki breaking behavior change Same API, different result enhancement Improvement on existing feature documentation done all docs done (wiki, api docs, lists on nlog-project.org, xmldocs) labels Aug 13, 2026
@snakefoot

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking behavior change Same API, different result documentation done all docs done (wiki, api docs, lists on nlog-project.org, xmldocs) enhancement Improvement on existing feature needs documentation on wiki platform support size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant