Commit 7d0e587
authored
# Description
Migrates the entire code base (Stack, Libraries and Applications) from
direct
`ILogger.LogInformation/LogError/LogWarning/LogDebug/LogTrace/LogCritical(...)`
calls to **source-generated `[LoggerMessage]` logging**, as tracked in
#3908.
Source-generated logging avoids boxing of value-type arguments, caches
the
message formatter, and emits an efficient `IsEnabled` check so a
disabled log
level costs nothing.
This is a behavior-preserving refactor: message text, levels and
structured
placeholders are unchanged; only the call shape changes.
## What changed
- **36 projects migrated.** Every static log call now goes through a
per-file
`internal static partial class <Class>Log` holding `[LoggerMessage]`
extension methods on `ILogger`, so call sites keep the natural
`logger.SomeEvent(...)` shape. Closely-related files that emit the same
messages share one log class (e.g. the encoders/decoders in
`Opc.Ua.Types`
share `EncodingLog`) to avoid duplication and CS0121 ambiguity.
- **Per-assembly event-id classes.** Each project has one
`internal static class <AssemblyToken>EventIds` (e.g. `CoreEventIds`,
`ClientEventIds`, `PubSubEventIds`) with a reserved `public const int`
offset block per log class. The assembly-token prefix avoids CS0436
collisions across `InternalsVisibleTo` boundaries.
- **`CA1873` enabled solution-wide** in `.editorconfig` now that the
whole
code base (including test, sample and tooling projects) is migrated, so
any
regression back to a direct `ILogger.Log*` call with an expensive
argument is
flagged. Every occurrence has been guarded with an `IsEnabled` check (or
the
check merged into an existing condition where the log was the sole body
of an
`if`/`else`, preserving side effects); the only suppressions are two Moq
`Verify` expression-tree sites, which are not executed log calls.
- **Dynamic log levels stay hand-written.** A handful of calls whose
level is
only known at runtime keep the structured `logger.Log(logLevel, ...)`
form
under an `if (logger.IsEnabled(logLevel))` guard — `[LoggerMessage]`
requires
a compile-time level.
- **netstandard duplicate-generator fix.** Projects that also pull in an
R9
package (`Microsoft.Extensions.Http.Resilience`, `.Compliance`,
`.Telemetry`)
get the `Microsoft.Gen.Logging` generator in addition to the in-box one;
on
`netstandard` both implement every partial method (CS0757). A single
`Directory.Build.targets` target removes the R9 analyzer on
`netstandard`
only (no-op elsewhere and where it is not referenced).
- **Shared/linked source files** that are compiled into more than one
project
(e.g. sample files linked into test projects) use self-contained literal
event ids instead of a per-assembly class the consumer does not compile.
- **Docs.** The authoring recipe (event-id convention, log-class
convention,
parameter rules, the `IsEnabled` guard, shared/linked files, and the
netstandard generator interaction) lives in the new
[`Docs/DeveloperGuide.md`](Docs/DeveloperGuide.md#add-a-log-message-source-generated);
`Docs/Diagnostics.md` keeps the runtime/observability side and links to
it.
- **Redaction preserved.** Log calls that previously wrapped sensitive
values
with `Redact.Create(...)` keep passing the `RedactionWrapper<T>`
(instead of
an eager `.ToString()`), so format-time redaction still applies — this
also
clears the CodeQL clear-text alerts introduced during the migration.
## Validation
- Full `UA.slnx` build passes with **0 errors / 0 warnings**; the
multi-target
test projects force every referenced library to build on
net472/net48/netstandard2.1/net8.0/net9.0/net10.0.
- No unguarded static `ILogger.Log*` calls remain anywhere (only the
guarded
dynamic-level calls); `CA1873` is clean across the full solution on
net10.0.
## Related Issues
- Fixes #3908
## Checklist
_Put an `x` in the boxes that apply. You can complete these step by step
after opening the PR._
- [ ] I have signed the
[CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf)
and read the
[CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md)
doc.
- [ ] I have added tests that prove my fix is effective or that my
feature works and increased code coverage.
- [x] I have added all necessary documentation.
- [x] I have verified that my changes do not introduce (new) build or
analyzer warnings.
- [ ] I ran **all** tests locally using the **UA.slnx** solution against
at least .net **framework** and .net **10**, and all passed.
- [ ] I fixed **all** failing and flaky tests in the CI pipelines and
**all** CodeQL warnings.
- [ ] I have addressed **all** PR feedback received.
1 parent ce2ccc7 commit 7d0e587
362 files changed
Lines changed: 15875 additions & 4533 deletions
File tree
- .github
- Applications
- ConsoleLdsServer
- ConsoleReferenceClient
- ConsoleReferencePubSubClient
- ConsoleReferenceServer
- McpServer
- MinimalBoilerServer
- PumpDeviceIntegrationServer
- Quickstarts.Servers
- Alarms
- AlarmControllers
- AlarmHolders
- Boiler
- DurableSubscription
- MemoryBuffer
- ReferenceServer
- SampleNodeManager
- TestData
- RedundantPubSub
- RedundantServer
- Docs
- Fuzzing/Common/Fuzz.Tools
- Libraries
- Opc.Ua.Client
- ComplexTypes
- Identity
- ModelChange
- NodeCache
- Session
- Reconnect
- Redundancy
- Subscription
- Subscription
- Classic
- WebApi
- Opc.Ua.Configuration
- Opc.Ua.Di.Server
- Builders
- Hosting
- Locking
- Opc.Ua.Gds.Client.Common
- Opc.Ua.Gds.Server.Common
- Diagnostics
- Hosting
- Identity
- Opc.Ua.Lds.Server
- Hosting
- Opc.Ua.PubSub.Adapter
- Actions
- DependencyInjection
- Publisher
- Session
- Subscriber
- Opc.Ua.PubSub.Diagnostics
- Capture
- DependencyInjection
- Opc.Ua.PubSub.Eth
- Channels
- Opc.Ua.PubSub.Kafka
- Internal
- Opc.Ua.PubSub.Mqtt
- Internal
- Opc.Ua.PubSub.Server
- Internal
- Opc.Ua.PubSub.Udp
- Dtls
- Opc.Ua.PubSub
- Application
- Configuration
- Connections
- Groups
- MetaData
- Redundancy
- Scheduling
- Security
- Sks
- StateMachine
- Transcoding
- Opc.Ua.Redundancy.Kubernetes
- Health
- LeaderElection
- Opc.Ua.Redundancy.PubSub
- Opc.Ua.Redundancy.Server
- Discovery
- Redundancy
- LoadDirection
- Sessions
- State
- Subscriptions
- Opc.Ua.Redundancy
- Raft
- Opc.Ua.Server
- Aggregates
- AliasNames
- Configuration
- Diagnostics
- Fluent
- Historian
- Hosting
- NodeManager
- MonitoredItem
- RoleBasedUserManagement
- UserDatabase
- UserManagement
- RuntimeNodeSet
- Server
- Session
- Subscription
- MonitoredItem
- QueueHandler
- Queue
- Opc.Ua.WotCon.Server
- Assets
- Stack
- Opc.Ua.Bindings.Https
- Https
- Tcp
- WebApi/Endpoints
- Opc.Ua.Core.Diagnostics
- Audit
- Bindings
- Capture
- Sources
- DependencyInjection
- Dissection
- Formats
- Frame
- KeyLog
- Replay
- Opc.Ua.Core.Schema
- ComplexTypes
- Opc.Ua.Core.Types
- State
- Opc.Ua.Core
- Redundancy
- Schema
- Security
- Certificates
- CertificateManager
- X509CertificateStore
- Extensions/Internal
- Stack
- Bindings
- Client
- Channels/Internal
- Configuration
- Https
- Server
- Tcp
- Transport
- Types/Utils
- Opc.Ua.Types
- BuiltIn
- Encoders
- Schema
- State
- Tests
- Opc.Ua.Client.ComplexTypes.Tests
- Opc.Ua.Client.TestFramework
- Opc.Ua.Client.Tests/Session
- Opc.Ua.Core.Diagnostics.Tests/Frame
- Opc.Ua.Gds.Tests
- Opc.Ua.Lds.Tests
- Opc.Ua.Server.TestFramework
- Opc.Ua.Server.Tests
- Opc.Ua.Stress.Tests/Channels/Fakes
- Tools/Opc.Ua.SourceGeneration.Core
- Generators
- Schema
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
481 | 481 | | |
482 | 482 | | |
483 | 483 | | |
484 | | - | |
485 | | - | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
486 | 489 | | |
487 | 490 | | |
488 | 491 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | | - | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| 106 | + | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
| |||
139 | 141 | | |
140 | 142 | | |
141 | 143 | | |
| 144 | + | |
142 | 145 | | |
143 | 146 | | |
144 | 147 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
184 | | - | |
| 184 | + | |
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
197 | 205 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
144 | | - | |
| 145 | + | |
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| |||
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
198 | 207 | | |
0 commit comments