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!
Cat a durat?
Nu puteau sa Debug.Write("File not found… ?
A durat cam o ora …
Intrebarea este – unde se afisa acel Debug.Write ?
Raspuns : vezi textWriterTraceListener
a.. ups