pedro-oliveira-sonarsource 74d74b4bf7 Tab removal.
2023-03-02 18:07:54 +01:00

50 lines
940 B
Plaintext

=== How to fix it in ASP.NET
include::../../common/fix/code-rationale.adoc[]
[cols="a"]
|===
h| Non-compliant code example
|
[source,csharp]
----
using System.Web;
using System.Web.Mvc;
public class ExampleController : Controller
{
[HttpGet]
public void Log(string data)
{
if (data != null)
{
_logger.Info("Log: " + data);
}
}
}
----
h| Compliant solution
|
[source,csharp]
----
using System.Web;
using System.Web.Mvc;
public class ExampleController : Controller
{
private static readonly log4net.ILog _logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
[HttpGet]
public void Log(string data)
{
if (data != null)
{
data = data.Replace('\n', '_').Replace('\r', '_');
_logger.Info("Log: " + data);
}
}
}
----
|===
include::../../common/fix/how-does-this-work.adoc[]