Lenka Rolinek | 9 May 2012 14:03
Favicon

RE: log4net usage in IIS7.5 ASP.NET MVC (multi assembly) application

Hi,

 

I am hoping someone can help…

 

We have a multi assembly ASP.NET MVC 3 application that runs on IIS7.5.

We are using log4net version 1.2.10.

We call log4net LogManager.GetLogger(“loggerName”).Error(“…”); from all assemblies of our web application.

 

Logging from all assemblies works when we run our web application on our development systems from MS Studio 2010.

I.e. the log contains logged information from all our application assemblies.

 

Logging from assemblies but the main one (the one from which log4net was registered, i.e. includes global.asax.cs file) does _NOT_ work when we run our web application installed on IIS7.5.

I.e. the log contains logged information from the application assembly only.

 

 

Following is a list of all log4net ‘configuration parts’ in our application:

 

1.       Log4net configuration is stored in a config file dedicated for log4net. 

The content of this file is below.

 

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

 

    <configSections>

        <!-- To support configuration file change detection. -->

        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

    </configSections>

 

    <!-- To turn the logging off completely, set threshold to OFF as shown below. -->

    <!-- log4net threshold="OFF" -->

    <log4net>

        <!-- Set root logger level to ERROR or above and its appender to RollingFile. -->

        <!-- Note, loggers that are not listed here will use root logger settings. -->

        <!-- Logger levels are -

        All  DEBUG  INFO  WARN  ERROR  FATAL  OFF

        -->

        <root>

            <level value="ALL" />

            <appender-ref ref="RollingFile" />

        </root>

        <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">

            <file value="logFile.txt" />

            <appendToFile value="true" />

            <staticLogFileName value="true" />

            <rollingStyle value="Size" />

            <maximumFileSize value="10MB" />

            <maxSizeRollBackups value="5" />

            <layout type="log4net.Layout.PatternLayout">

                <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss} %5level %logger: %message%newline" />

            </layout>

                     <!-- example of exclude filter

            <filter type="log4net.Filter.LoggerMatchFilter">

                <loggerToMatch value="TextToMatch" />

                <acceptOnMatch value="false" />

            </filter>

                     -->

        </appender>

    </log4net>

 

</configuration>

 

 

2.       We inititialise the logging in global.asax.cs file using the following API and we are positive the location of the configuration file is correct.

 

      protected void Application_Start()

      {

         try

         {

            // Configure log4net

            string webConfigPath = HttpContext.Current.Server.MapPath("~") + <at> "Web.log4net.config";

            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(webConfigPath));

 

3.       We also give the web application pool privileges to create/write log file in the folder that is meant to contain log files.

 

4.       We also enabled getting HttpContext as suggested on this discussion - http://sgomez.blogspot.com.au/2009/03/log4net-with-wcf-services.html

   [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

   [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

   public class DataView

   {

   …

   }

 

 

Is there anything else we must do?

Is it expected to work with log4net version 1.2.10?

Any suggestions?

 

 

Regards,

Lenka

 


_____________________________________________________________________

This email is intended only for the use of the individual or entity named above and may contain information that is confidential and/or privileged. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this Email is strictly prohibited. If you have received this Email in error, please notify us immediately by return email or telephone +61 2 9966 1066 and destroy the original message. Thank You
_______________________________________________________________________
Todd | 9 May 2012 15:26
Picon
Favicon

Re: log4net usage in IIS7.5 ASP.NET MVC (multi assembly) application

Could it be permissions? Remember, when you run locally, you're running under your account. When you run on a remote server, it's typically configured to run under a service account. That account needs to have permission to log. Furthermore, if you're using impersonation, the STARTUP events in global.asax.cs runs under the pool account, but code on the user thread runs under the impersonated account.
 
This can be a pain to debug because l4n silently fails under a situation like this and then disables the appender for the rest of that application's lifetime.

From: Lenka Rolinek <Lenka.Rolinek <at> ir.com>
To: log4net-user <at> logging.apache.org
Sent: Wednesday, May 9, 2012 8:03 AM
Subject: RE: log4net usage in IIS7.5 ASP.NET MVC (multi assembly) application

Hi,
 
I am hoping someone can help…
 
We have a multi assembly ASP.NET MVC 3 application that runs on IIS7.5.
We are using log4net version 1.2.10.
We call log4net LogManager.GetLogger(“loggerName”).Error(“…”); from all assemblies of our web application.
 
Logging from all assemblies works when we run our web application on our development systems from MS Studio 2010.
I.e. the log contains logged information from all our application assemblies.
 
Logging from assemblies but the main one (the one from which log4net was registered, i.e. includes global.asax.cs file) does _NOT_ work when we run our web application installed on IIS7.5.
I.e. the log contains logged information from the application assembly only.
 
 
Following is a list of all log4net ‘configuration parts’ in our application:
 
1.       Log4net configuration is stored in a config file dedicated for log4net. 
The content of this file is below.
 
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 
    <configSections>
        <!-- To support configuration file change detection. -->
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    </configSections>
 
    <!-- To turn the logging off completely, set threshold to OFF as shown below. -->
    <!-- log4net threshold="OFF" -->
    <log4net>
        <!-- Set root logger level to ERROR or above and its appender to RollingFile. -->
        <!-- Note, loggers that are not listed here will use root logger settings. -->
        <!-- Logger levels are -
        All  DEBUG  INFO  WARN  ERROR  FATAL  OFF
        -->
        <root>
            <level value="ALL" />
            <appender-ref ref="RollingFile" />
        </root>
        <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
            <file value="logFile.txt" />
            <appendToFile value="true" />
            <staticLogFileName value="true" />
            <rollingStyle value="Size" />
            <maximumFileSize value="10MB" />
            <maxSizeRollBackups value="5" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss} %5level %logger: %message%newline" />
            </layout>
                     <!-- example of exclude filter
            <filter type="log4net.Filter.LoggerMatchFilter">
                <loggerToMatch value="TextToMatch" />
                <acceptOnMatch value="false" />
            </filter>
                     -->
        </appender>
    </log4net>
 
</configuration>
 
 
2.       We inititialise the logging in global.asax.cs file using the following API and we are positive the location of the configuration file is correct.
 
      protected void Application_Start()
      {
         try
         {
            // Configure log4net
            string webConfigPath = HttpContext.Current.Server.MapPath("~") + <at> "Web.log4net.config";
            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(webConfigPath));
 
3.       We also give the web application pool privileges to create/write log file in the folder that is meant to contain log files.
 
4.       We also enabled getting HttpContext as suggested on this discussion - http://sgomez.blogspot.com.au/2009/03/log4net-with-wcf-services.html
   [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
   [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
   public class DataView
   {
   …
   }
 
 
Is there anything else we must do?
Is it expected to work with log4net version 1.2.10?
Any suggestions?
 
 
Regards,
Lenka
 

_____________________________________________________________________

This email is intended only for the use of the individual or entity named above and may contain information that is confidential and/or privileged. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this Email is strictly prohibited. If you have received this Email in error, please notify us immediately by return email or telephone +61 2 9966 1066 and destroy the original message. Thank You
_______________________________________________________________________


Venkatasamy, Vanitha | 9 May 2012 16:07
Favicon

RE: log4net usage in IIS7.5 ASP.NET MVC (multi assembly) application

Hi,

  I have implemented the Log4Net for .Net3.5 web application with IIS 7. Ours is multiple environment like windows 2003 iis6 ,windows 2008 iis 7 and windows7 IIS7 like that.

Below are the few suggestions you can try ,

 

1.       Implement the log4net in a separate dll and call it in the Global.asax.cs file like below.

 

    void Application_Start(object sender, EventArgs e)

    {

        // Code that runs on application startup

log4net.Config.XmlConfigurator.Configure();

 }

 

       void Application_Error(object sender, EventArgs e)

       {

 

        // Code that runs when an unhandled error occurs

        string strErrorPage;       

  Exception objErr = Server.GetLastError().GetBaseException();

                   dllname.ErrorLogging logger = new dllname.ErrorLogging();

strErrorPage = logger.logEventError(System.Configuration.ConfigurationManager.AppSettings["Source"].ToString(), System.Configuration.ConfigurationManager.AppSettings["Log"].ToString(),  HttpContext.Current, Request, objErr, strBotPath);

}

 

 

2.       You can have the initialization and error logging in that dll . In the dll app log the error as below

 

    public static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

       public String logEventError(String sourceName, String logName, HttpContext errContext, HttpRequest errRequest, Exception objErr,  string strBotListPath)

        {

               log4net.Config.XmlConfigurator.Configure();

                bool y = LogManager.GetRepository().Configured;

            log4net.ThreadContext.Properties["EventID"] = 5;

                if (objErr.GetType() == typeof(HttpException))

             {

               checkException = (HttpException)objErr;

           }

             if ((log.IsErrorEnabled) && ((checkException.GetHttpCode() == 500) || (checkException.GetHttpCode() == 404)))

               {

        

                

                if(checkException.GetHttpCode() == 500)              

                log4net.ThreadContext.Properties["Category"] = "500";

                else

                log4net.ThreadContext.Properties["Category"] = "404";

 

                log.Error("Error" + sbErrorMessage.ToString() + "Log Name " + logn + "Repository" + logr);

 

           }

     }

 

 

3.       I also encountered few permissions issues like authorization to write to a event viewer, but yours is  a text file so just make sure the folder that contains the .txt file has permission for IUSRS or Network_Service.

 

4.       Try to access the config file as

 

log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.GetDirectoryName(Assembly.GetAssembly(GetType()).Location) + <at> "\" + "xxx.config"));

 

        5.In the web.config file enable the log4net debugging as below ,it might show you the actual error

 

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

      <system.diagnostics>

        <trace autoflush="true">

          <listeners>

          <add name="textWriterTraceListener"

           type="System.Diagnostics.TextWriterTraceListener"

           initializeData="C:\log-file-debug.txt" />

         </listeners>

       </trace>

     </system.diagnostics>

 

Hope it helps u …

 

Thanks,

Vanitha

 

From: Lenka Rolinek [mailto:Lenka.Rolinek <at> ir.com]
Sent: Wednesday, May 09, 2012 8:03 AM
To: log4net-user <at> logging.apache.org
Subject: RE: log4net usage in IIS7.5 ASP.NET MVC (multi assembly) application

 

Hi,

 

I am hoping someone can help…

 

We have a multi assembly ASP.NET MVC 3 application that runs on IIS7.5.

We are using log4net version 1.2.10.

We call log4net LogManager.GetLogger(“loggerName”).Error(“…”); from all assemblies of our web application.

 

Logging from all assemblies works when we run our web application on our development systems from MS Studio 2010.

I.e. the log contains logged information from all our application assemblies.

 

Logging from assemblies but the main one (the one from which log4net was registered, i.e. includes global.asax.cs file) does _NOT_ work when we run our web application installed on IIS7.5.

I.e. the log contains logged information from the application assembly only.

 

 

Following is a list of all log4net ‘configuration parts’ in our application:

 

1.       Log4net configuration is stored in a config file dedicated for log4net. 

The content of this file is below.

 

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

 

    <configSections>

        <!-- To support configuration file change detection. -->

        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

    </configSections>

 

    <!-- To turn the logging off completely, set threshold to OFF as shown below. -->

    <!-- log4net threshold="OFF" -->

    <log4net>

        <!-- Set root logger level to ERROR or above and its appender to RollingFile. -->

        <!-- Note, loggers that are not listed here will use root logger settings. -->

        <!-- Logger levels are -

        All  DEBUG  INFO  WARN  ERROR  FATAL  OFF

        -->

        <root>

            <level value="ALL" />

            <appender-ref ref="RollingFile" />

        </root>

        <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">

            <file value="logFile.txt" />

            <appendToFile value="true" />

            <staticLogFileName value="true" />

            <rollingStyle value="Size" />

            <maximumFileSize value="10MB" />

            <maxSizeRollBackups value="5" />

            <layout type="log4net.Layout.PatternLayout">

                <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss} %5level %logger: %message%newline" />

            </layout>

                     <!-- example of exclude filter

            <filter type="log4net.Filter.LoggerMatchFilter">

                <loggerToMatch value="TextToMatch" />

                <acceptOnMatch value="false" />

            </filter>

                     -->

        </appender>

    </log4net>

 

</configuration>

 

 

2.       We inititialise the logging in global.asax.cs file using the following API and we are positive the location of the configuration file is correct.

 

      protected void Application_Start()

      {

         try

         {

            // Configure log4net

            string webConfigPath = HttpContext.Current.Server.MapPath("~") + <at> "Web.log4net.config";

            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(webConfigPath));

 

3.       We also give the web application pool privileges to create/write log file in the folder that is meant to contain log files.

 

4.       We also enabled getting HttpContext as suggested on this discussion - http://sgomez.blogspot.com.au/2009/03/log4net-with-wcf-services.html

   [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

   [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

   public class DataView

   {

   …

   }

 

 

Is there anything else we must do?

Is it expected to work with log4net version 1.2.10?

Any suggestions?

 

 

Regards,

Lenka

 


_____________________________________________________________________

This email is intended only for the use of the individual or entity named above and may contain information that is confidential and/or privileged. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this Email is strictly prohibited. If you have received this Email in error, please notify us immediately by return email or telephone +61 2 9966 1066 and destroy the original message. Thank You
_______________________________________________________________________



This message contains Devin Group confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by e-mail if you have received this e-mail in error and delete this e-mail from your system. E-mail transmissions cannot be guaranteed secure, error-free and information could be intercepted, corrupted, lost, destroyed, arrive late, incomplete, or contain viruses. The sender therefore does not accept liability for errors or omissions in the contents of this message which may arise as result of transmission. If verification is required please request hard-copy version.
Lenka Rolinek | 11 May 2012 06:29
Favicon

RE: log4net usage in IIS7.5 ASP.NET MVC (multi assembly) application

xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:a="urn:schemas-microsoft-com:office:access" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:b="urn:schemas-microsoft-com:office:publisher" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:odc="urn:schemas-microsoft-com:office:odc" xmlns:oa="urn:schemas-microsoft-com:office:activation" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:q="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rtc="http://microsoft.com/officenet/conferencing" xmlns:D="DAV:" xmlns:Repl="http://schemas.microsoft.com/repl/" xmlns:mt="http://schemas.microsoft.com/sharepoint/soap/meetings/" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ppda="http://www.passport.com/NameSpace.xsd" xmlns:ois="http://schemas.microsoft.com/sharepoint/soap/ois/" xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" xmlns:udc="http://schemas.microsoft.com/data/udc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sub="http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/" xmlns:ec="http://www.w3.org/2001/04/xmlenc#" xmlns:sp="http://schemas.microsoft.com/sharepoint/" xmlns:sps="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:udcs="http://schemas.microsoft.com/data/udc/soap" xmlns:udcxf="http://schemas.microsoft.com/data/udc/xmlfile" xmlns:udcp2p="http://schemas.microsoft.com/data/udc/parttopart" xmlns:wf="http://schemas.microsoft.com/sharepoint/soap/workflow/" xmlns:dsss="http://schemas.microsoft.com/office/2006/digsig-setup" xmlns:dssi="http://schemas.microsoft.com/office/2006/digsig" xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" xmlns:mver="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:mrels="http://schemas.openxmlformats.org/package/2006/relationships" xmlns:spwp="http://microsoft.com/sharepoint/webpartpages" xmlns:ex12t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ex12m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:pptsl="http://schemas.microsoft.com/sharepoint/soap/SlideLibrary/" xmlns:spsl="http://microsoft.com/webservices/SharePointPortalServer/PublishedLinksService" xmlns:Z="urn:schemas-microsoft-com:" xmlns:st="" xmlns="http://www.w3.org/TR/REC-html40">

Hi Vanitha,

 

Enabling log4net debugging help me to find the problem.

 

Thank you for your help,

Lenka

 

 

From: Venkatasamy, Vanitha [mailto:Vanitha.Venkatasamy <at> xpandcorp.com]
Sent: 10. května 2012 0:08
To: Log4NET User
Subject: RE: log4net usage in IIS7.5 ASP.NET MVC (multi assembly) application

 

Hi,

  I have implemented the Log4Net for .Net3.5 web application with IIS 7. Ours is multiple environment like windows 2003 iis6 ,windows 2008 iis 7 and windows7 IIS7 like that.

Below are the few suggestions you can try ,

 

1.       Implement the log4net in a separate dll and call it in the Global.asax.cs file like below.

 

    void Application_Start(object sender, EventArgs e)

    {

        // Code that runs on application startup

log4net.Config.XmlConfigurator.Configure();

 }

 

       void Application_Error(object sender, EventArgs e)

       {

 

        // Code that runs when an unhandled error occurs

        string strErrorPage;       

  Exception objErr = Server.GetLastError().GetBaseException();

                   dllname.ErrorLogging logger = new dllname.ErrorLogging();

strErrorPage = logger.logEventError(System.Configuration.ConfigurationManager.AppSettings["Source"].ToString(), System.Configuration.ConfigurationManager.AppSettings["Log"].ToString(),  HttpContext.Current, Request, objErr, strBotPath);

}

 

 

2.       You can have the initialization and error logging in that dll . In the dll app log the error as below

 

    public static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

       public String logEventError(String sourceName, String logName, HttpContext errContext, HttpRequest errRequest, Exception objErr,  string strBotListPath)

        {

               log4net.Config.XmlConfigurator.Configure();

                bool y = LogManager.GetRepository().Configured;

            log4net.ThreadContext.Properties["EventID"] = 5;

                if (objErr.GetType() == typeof(HttpException))

             {

               checkException = (HttpException)objErr;

           }

             if ((log.IsErrorEnabled) && ((checkException.GetHttpCode() == 500) || (checkException.GetHttpCode() == 404)))

               {

        

                

                if(checkException.GetHttpCode() == 500)              

                log4net.ThreadContext.Properties["Category"] = "500";

                else

                log4net.ThreadContext.Properties["Category"] = "404";

 

                log.Error("Error" + sbErrorMessage.ToString() + "Log Name " + logn + "Repository" + logr);

 

           }

     }

 

 

3.       I also encountered few permissions issues like authorization to write to a event viewer, but yours is  a text file so just make sure the folder that contains the .txt file has permission for IUSRS or Network_Service.

 

4.       Try to access the config file as

 

log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.GetDirectoryName(Assembly.GetAssembly(GetType()).Location) + <at> "\" + "xxx.config"));

 

        5.In the web.config file enable the log4net debugging as below ,it might show you the actual error

 

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

      <system.diagnostics>

        <trace autoflush="true">

          <listeners>

          <add name="textWriterTraceListener"

           type="System.Diagnostics.TextWriterTraceListener"

           initializeData="C:\log-file-debug.txt" />

         </listeners>

       </trace>

     </system.diagnostics>

 

Hope it helps u …

 

Thanks,

Vanitha

 

From: Lenka Rolinek [mailto:Lenka.Rolinek <at> ir.com]
Sent: Wednesday, May 09, 2012 8:03 AM
To: log4net-user <at> logging.apache.org
Subject: RE: log4net usage in IIS7.5 ASP.NET MVC (multi assembly) application

 

Hi,

 

I am hoping someone can help…

 

We have a multi assembly ASP.NET MVC 3 application that runs on IIS7.5.

We are using log4net version 1.2.10.

We call log4net LogManager.GetLogger(“loggerName”).Error(“…”); from all assemblies of our web application.

 

Logging from all assemblies works when we run our web application on our development systems from MS Studio 2010.

I.e. the log contains logged information from all our application assemblies.

 

Logging from assemblies but the main one (the one from which log4net was registered, i.e. includes global.asax.cs file) does _NOT_ work when we run our web application installed on IIS7.5.

I.e. the log contains logged information from the application assembly only.

 

 

Following is a list of all log4net ‘configuration parts’ in our application:

 

1.       Log4net configuration is stored in a config file dedicated for log4net. 

The content of this file is below.

 

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

 

    <configSections>

        <!-- To support configuration file change detection. -->

        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

    </configSections>

 

    <!-- To turn the logging off completely, set threshold to OFF as shown below. -->

    <!-- log4net threshold="OFF" -->

    <log4net>

        <!-- Set root logger level to ERROR or above and its appender to RollingFile. -->

        <!-- Note, loggers that are not listed here will use root logger settings. -->

        <!-- Logger levels are -

        All  DEBUG  INFO  WARN  ERROR  FATAL  OFF

        -->

        <root>

            <level value="ALL" />

            <appender-ref ref="RollingFile" />

        </root>

        <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">

            <file value="logFile.txt" />

            <appendToFile value="true" />

            <staticLogFileName value="true" />

            <rollingStyle value="Size" />

            <maximumFileSize value="10MB" />

            <maxSizeRollBackups value="5" />

            <layout type="log4net.Layout.PatternLayout">

                <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss} %5level %logger: %message%newline" />

            </layout>

                     <!-- example of exclude filter

            <filter type="log4net.Filter.LoggerMatchFilter">

                <loggerToMatch value="TextToMatch" />

                <acceptOnMatch value="false" />

            </filter>

                     -->

        </appender>

    </log4net>

 

</configuration>

 

 

2.       We inititialise the logging in global.asax.cs file using the following API and we are positive the location of the configuration file is correct.

 

      protected void Application_Start()

      {

         try

         {

            // Configure log4net

            string webConfigPath = HttpContext.Current.Server.MapPath("~") + <at> "Web.log4net.config";

            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(webConfigPath));

 

3.       We also give the web application pool privileges to create/write log file in the folder that is meant to contain log files.

 

4.       We also enabled getting HttpContext as suggested on this discussion - http://sgomez.blogspot.com.au/2009/03/log4net-with-wcf-services.html

   [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

   [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

   public class DataView

   {

   …

   }

 

 

Is there anything else we must do?

Is it expected to work with log4net version 1.2.10?

Any suggestions?

 

 

Regards,

Lenka

 


_____________________________________________________________________

This email is intended only for the use of the individual or entity named above and may contain information that is confidential and/or privileged. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this Email is strictly prohibited. If you have received this Email in error, please notify us immediately by return email or telephone +61 2 9966 1066 and destroy the original message. Thank You
_______________________________________________________________________

 


This message contains Devin Group confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by e-mail if you have received this e-mail in error and delete this e-mail from your system. E-mail transmissions cannot be guaranteed secure, error-free and information could be intercepted, corrupted, lost, destroyed, arrive late, incomplete, or contain viruses. The sender therefore does not accept liability for errors or omissions in the contents of this message which may arise as result of transmission. If verification is required please request hard-copy version.

_____________________________________________________________________
This e-mail has been scanned for viruses by MCI's Internet Managed
Scanning Services - powered by MessageLabs. For further information
visit http://www.mci.com


_____________________________________________________________________

This email is intended only for the use of the individual or entity named above and may contain information that is confidential and/or privileged. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this Email is strictly prohibited. If you have received this Email in error, please notify us immediately by return email or telephone +61 2 9966 1066 and destroy the original message. Thank You
_______________________________________________________________________
Venkatasamy, Vanitha | 11 May 2012 15:09
Favicon

RE: log4net usage in IIS7.5 ASP.NET MVC (multi assembly) application

I am glad it helped you…

 

From: Lenka Rolinek [mailto:Lenka.Rolinek <at> ir.com]
Sent: Friday, May 11, 2012 12:30 AM
To: Log4NET User
Subject: RE: log4net usage in IIS7.5 ASP.NET MVC (multi assembly) application

 

Hi Vanitha,

 

Enabling log4net debugging help me to find the problem.

 

Thank you for your help,

Lenka

 

 

From: Venkatasamy, Vanitha [mailto:Vanitha.Venkatasamy <at> xpandcorp.com]
Sent: 10. května 2012 0:08
To: Log4NET User
Subject: RE: log4net usage in IIS7.5 ASP.NET MVC (multi assembly) application

 

Hi,

  I have implemented the Log4Net for .Net3.5 web application with IIS 7. Ours is multiple environment like windows 2003 iis6 ,windows 2008 iis 7 and windows7 IIS7 like that.

Below are the few suggestions you can try ,

 

1.       Implement the log4net in a separate dll and call it in the Global.asax.cs file like below.

 

    void Application_Start(object sender, EventArgs e)

    {

        // Code that runs on application startup

log4net.Config.XmlConfigurator.Configure();

 }

 

       void Application_Error(object sender, EventArgs e)

       {

 

        // Code that runs when an unhandled error occurs

        string strErrorPage;       

  Exception objErr = Server.GetLastError().GetBaseException();

                   dllname.ErrorLogging logger = new dllname.ErrorLogging();

strErrorPage = logger.logEventError(System.Configuration.ConfigurationManager.AppSettings["Source"].ToString(), System.Configuration.ConfigurationManager.AppSettings["Log"].ToString(),  HttpContext.Current, Request, objErr, strBotPath);

}

 

 

2.       You can have the initialization and error logging in that dll . In the dll app log the error as below

 

    public static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

       public String logEventError(String sourceName, String logName, HttpContext errContext, HttpRequest errRequest, Exception objErr,  string strBotListPath)

        {

               log4net.Config.XmlConfigurator.Configure();

                bool y = LogManager.GetRepository().Configured;

            log4net.ThreadContext.Properties["EventID"] = 5;

                if (objErr.GetType() == typeof(HttpException))

             {

               checkException = (HttpException)objErr;

           }

             if ((log.IsErrorEnabled) && ((checkException.GetHttpCode() == 500) || (checkException.GetHttpCode() == 404)))

               {

        

                

                if(checkException.GetHttpCode() == 500)              

                log4net.ThreadContext.Properties["Category"] = "500";

                else

                log4net.ThreadContext.Properties["Category"] = "404";

 

                log.Error("Error" + sbErrorMessage.ToString() + "Log Name " + logn + "Repository" + logr);

 

           }

     }

 

 

3.       I also encountered few permissions issues like authorization to write to a event viewer, but yours is  a text file so just make sure the folder that contains the .txt file has permission for IUSRS or Network_Service.

 

4.       Try to access the config file as

 

log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.GetDirectoryName(Assembly.GetAssembly(GetType()).Location) + <at> "\" + "xxx.config"));

 

        5.In the web.config file enable the log4net debugging as below ,it might show you the actual error

 

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

      <system.diagnostics>

        <trace autoflush="true">

          <listeners>

          <add name="textWriterTraceListener"

           type="System.Diagnostics.TextWriterTraceListener"

           initializeData="C:\log-file-debug.txt" />

         </listeners>

       </trace>

     </system.diagnostics>

 

Hope it helps u …

 

Thanks,

Vanitha

 

From: Lenka Rolinek [mailto:Lenka.Rolinek <at> ir.com]
Sent: Wednesday, May 09, 2012 8:03 AM
To: log4net-user <at> logging.apache.org
Subject: RE: log4net usage in IIS7.5 ASP.NET MVC (multi assembly) application

 

Hi,

 

I am hoping someone can help…

 

We have a multi assembly ASP.NET MVC 3 application that runs on IIS7.5.

We are using log4net version 1.2.10.

We call log4net LogManager.GetLogger(“loggerName”).Error(“…”); from all assemblies of our web application.

 

Logging from all assemblies works when we run our web application on our development systems from MS Studio 2010.

I.e. the log contains logged information from all our application assemblies.

 

Logging from assemblies but the main one (the one from which log4net was registered, i.e. includes global.asax.cs file) does _NOT_ work when we run our web application installed on IIS7.5.

I.e. the log contains logged information from the application assembly only.

 

 

Following is a list of all log4net ‘configuration parts’ in our application:

 

1.       Log4net configuration is stored in a config file dedicated for log4net. 

The content of this file is below.

 

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

 

    <configSections>

        <!-- To support configuration file change detection. -->

        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

    </configSections>

 

    <!-- To turn the logging off completely, set threshold to OFF as shown below. -->

    <!-- log4net threshold="OFF" -->

    <log4net>

        <!-- Set root logger level to ERROR or above and its appender to RollingFile. -->

        <!-- Note, loggers that are not listed here will use root logger settings. -->

        <!-- Logger levels are -

        All  DEBUG  INFO  WARN  ERROR  FATAL  OFF

        -->

        <root>

            <level value="ALL" />

            <appender-ref ref="RollingFile" />

        </root>

        <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">

            <file value="logFile.txt" />

            <appendToFile value="true" />

            <staticLogFileName value="true" />

            <rollingStyle value="Size" />

            <maximumFileSize value="10MB" />

            <maxSizeRollBackups value="5" />

            <layout type="log4net.Layout.PatternLayout">

                <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss} %5level %logger: %message%newline" />

            </layout>

                     <!-- example of exclude filter

            <filter type="log4net.Filter.LoggerMatchFilter">

                <loggerToMatch value="TextToMatch" />

                <acceptOnMatch value="false" />

            </filter>

                     -->

        </appender>

    </log4net>

 

</configuration>

 

 

2.       We inititialise the logging in global.asax.cs file using the following API and we are positive the location of the configuration file is correct.

 

      protected void Application_Start()

      {

         try

         {

            // Configure log4net

            string webConfigPath = HttpContext.Current.Server.MapPath("~") + <at> "Web.log4net.config";

            log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(webConfigPath));

 

3.       We also give the web application pool privileges to create/write log file in the folder that is meant to contain log files.

 

4.       We also enabled getting HttpContext as suggested on this discussion - http://sgomez.blogspot.com.au/2009/03/log4net-with-wcf-services.html

   [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

   [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]

   public class DataView

   {

   …

   }

 

 

Is there anything else we must do?

Is it expected to work with log4net version 1.2.10?

Any suggestions?

 

 

Regards,

Lenka

 


_____________________________________________________________________

This email is intended only for the use of the individual or entity named above and may contain information that is confidential and/or privileged. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this Email is strictly prohibited. If you have received this Email in error, please notify us immediately by return email or telephone +61 2 9966 1066 and destroy the original message. Thank You
_______________________________________________________________________

 


This message contains Devin Group confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by e-mail if you have received this e-mail in error and delete this e-mail from your system. E-mail transmissions cannot be guaranteed secure, error-free and information could be intercepted, corrupted, lost, destroyed, arrive late, incomplete, or contain viruses. The sender therefore does not accept liability for errors or omissions in the contents of this message which may arise as result of transmission. If verification is required please request hard-copy version.

_____________________________________________________________________
This e-mail has been scanned for viruses by MCI's Internet Managed
Scanning Services - powered by MessageLabs. For further information
visit http://www.mci.com


_____________________________________________________________________

This email is intended only for the use of the individual or entity named above and may contain information that is confidential and/or privileged. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this Email is strictly prohibited. If you have received this Email in error, please notify us immediately by return email or telephone +61 2 9966 1066 and destroy the original message. Thank You
_______________________________________________________________________



This message contains Devin Group confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.
Please notify the sender immediately by e-mail if you have received this e-mail in error and delete this e-mail from your system. E-mail transmissions cannot be guaranteed secure, error-free and information could be intercepted, corrupted, lost, destroyed, arrive late, incomplete, or contain viruses. The sender therefore does not accept liability for errors or omissions in the contents of this message which may arise as result of transmission. If verification is required please request hard-copy version.

Gmane