rspec/rules/S106/csharp/rule.adoc
Angelo Buono e8cd1b485d
Modify rule S106: Migrate to LayC - Standard outputs should not be used directly to log anything (#3280)
Co-authored-by: Marco Borgeaud <89914223+marco-antognini-sonarsource@users.noreply.github.com>
Co-authored-by: Zsolt Kolbay <121798625+zsolt-kolbay-sonarsource@users.noreply.github.com>
2023-10-16 18:57:06 +00:00

77 lines
1.3 KiB
Plaintext

:language_std_outputs: Console
== Why is this an issue?
include::../description.adoc[]
=== Exceptions
The rule doesn't raise an issue for:
* Console Applications
* Calls in methods decorated with `[Conditional ("DEBUG")]`
* Calls included in DEBUG preprocessor branches (``++#if DEBUG++``)
=== Code examples
The following noncompliant code:
[source,csharp,diff-id=1,diff-type=noncompliant]
----
public class MyClass
{
private void DoSomething()
{
// ...
Console.WriteLine("My Message"); // Noncompliant
// ...
}
}
----
Could be replaced by:
[source,csharp,diff-id=1,diff-type=compliant]
----
public class MyClass
{
private readonly ILogger _logger;
// ...
private void DoSomething()
{
// ...
_logger.LogInformation("My Message");
// ...
}
}
----
== Resources
* https://owasp.org/Top10/A09_2021-Security_Logging_and_Monitoring_Failures/[OWASP Top 10 2021 Category A9] - Security Logging and Monitoring Failures
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
=== on 30 Aug 2018, 15:48:10 Nicolas Harraudeau wrote:
Previously RSPEC-2556
See Gendarme DisableDebuggingCodeRule
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]