50 lines
959 B
Plaintext
Raw Normal View History

2022-08-23 10:07:08 +02:00
=== 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', '_').Replace('\t', '_');
_logger.Info("Log: " + data);
}
}
}
----
|===
include::../../common/fix/how-does-this-work.adoc[]