log4net si asp.net MVC – debug!

Pentru cei care se mai chinuie ca , desi au configurat log4net corect, in asp.net mvc nu logheaza nimic…

Inceput : pus un log4net.config, pus in global.asax in start Application :

System.IO.FileInfo s=new System.IO.FileInfo(Server.MapPath("log4net.config"));            
log4net.Config.XmlConfigurator.ConfigureAndWatch(s);

pus un un controller in homecontroller de tipul :

public ActionResult error()
        {
            return View("Error", new HandleErrorInfo(new ArgumentException("asd"), "home", "error" + _logger.IsErrorEnabled));
        }

 

Cind browsam http://localhost/site/home/error , imi afisa “error” FALSE

Cind faceam debug din VS ,imi afisa “error” TRUE .

Am innebunit cautind rezolvarea … si, dupa mai multe incercari nereusite, m-am hotarit sa fac debug.

In web.config sub <configuration> :

<appSettings>
        <add key="log4net.Internal.Debug" value="true"/>
    </appSettings>

<system.diagnostics>
        <trace autoflush="true">
            <listeners>
                <add
                  name="textWriterTraceListener"
                  type="System.Diagnostics.TextWriterTraceListener"
                  initializeData="<cale catre site>\log\log4net.txt" />

<!– vedeti sa aveti drept de scriere pentru user-ul de aspnet–>

            </listeners>

        </trace>

    </system.diagnostics>

<system.web>
        <trace enabled="true"/>

Si mi-a aparut :

log4net: XmlConfigurator: config file [<site>\home\log4net.config] not found.

Asa ca am schimbat  :

System.IO.FileInfo s=new System.IO.FileInfo(Server.MapPath("log4net.config"));            
cu

System.IO.FileInfo s=new System.IO.FileInfo(Server.MapPath("~/log4net.config"));  

 

SI GATA!

3 thoughts on “log4net si asp.net MVC – debug!

Leave a Reply

Your email address will not be published. Required fields are marked *