== How to fix it in ASP.NET

=== Code examples

include::../../common/fix/code-rationale.adoc[]

==== Noncompliant code example

[source,csharp,diff-id=1,diff-type=noncompliant]
----
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)
        {
            _logger.Info("Log: " + data); // Noncompliant
        }
    }
}
----

==== Compliant solution

[source,csharp,diff-id=1,diff-type=compliant]
----
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[]
