logging-log4net-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ron Grabowski <rongrabow...@yahoo.com>
Subject Re: no log file is created
Date Wed, 27 Jun 2007 21:14:20 GMT
Have you verified that you can create a FileStream to the directory and create a file? If log4net
has been initialized correctly, this code will create a file named RollingFileAppender.txt
that contains the text Hello World!:

foreach (FileAppender appender in log.Logger.Repository.GetAppenders())
{
    if (appender != null)
    {
        string directoryName = Path.GetDirectoryName(appender.File);

        string tempFile = Path.Combine(directoryName, appender.Name + ".txt");

        using (FileStream fileStream = File.OpenWrite(tempFile))
        {
            using (StreamWriter streamWriter = new StreamWriter(fileStream))
            {
                streamWriter.WriteLine("Hello World!");
            }
        }
    }
}


----- Original Message ----

From: Samuel Rochas <samuel.rochas@iesedu.com>

To: Log4NET User <log4net-user@logging.apache.org>

Sent: Wednesday, June 27, 2007 11:51:34 AM

Subject: Re: no log file is created



          Dear Alvaro, 

 

 I've changed my config according to yours but I still can't log. How could I try to troubleshoot?

 

 Samuel

 

 Alvaro Rozo escribió:    Samuel,

   

 Try the following, this works for me in my web.config:

   

 <?xml version="1.0"?>

 <configuration>

 <configSections>

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

 </configSections>

   More web config stuff

     <log4net>

         <!-- RollingFileAppender looks after rolling over files by size or date -->

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

             <file value="C:\\Dev\\Test\\log\\log.txt"/>   

             <param name="AppendToFile" value="true"/>

             <param name="MaxSizeRollBackups" value="10"/>

             <param name="MaximumFileSize" value="100000"/>   

             <param name="RollingStyle" value="Size"/>

             <param name="StaticLogFileName" value="true"/>

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

                 <param name="ConversionPattern" value="="%date [%thread] %-5level %logger
[%ndc] - %message%newline"/>

             </layout>

         </appender>   

         <!-- Setup the root category, add the appenders and set the default level -->

         <root>

             <level value="DEBUG"/>

             <appender-ref ref="RollingFileAppender"/>   

         </root>

     </log4net>

 </configuration>

   

   

 On 6/27/07, Samuel Rochas <samuel.rochas@iesedu.com> wrote:

 > 

 > Dear Michael, 

 > 

 > I've tried to define an EventLogAppender as shown bellow, but still nothing happens.
I may have a bigger problem ;-)

 > In the Solution Explorer view, I can see the Bin directory with the log4net.dll inside,
so for me it looks good.

 > 

 > If I use an external config file for log4net, where do I tell my application to use
it?

 > 

 > Thanx

 > Samuel

 > 

 > web.config:

 > <configuration xmlns="   http://schemas.microsoft.com/.NetConfiguration/v2.0";>

 >   <!-- Register a section handler for the log4net section -->

 >   <configSections>   

 >     <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />

 >   </configSections>

 >   <appSettings>

 >   </appSettings>

 >   <!-- This section contains the log4net configuration settings -->   

 >   <log4net>

 >     <!-- Define some output appenders -->

 >     <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >

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

 >         <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}]
- %message%newline" />

 >       </layout>

 >     </appender>   

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

 >       <file value="C:\Dev\Test\log\log.txt" />

 >       <appendToFile value="true" />   

 >       <maxSizeRollBackups value="10" />

 >       <maximumFileSize value="1024KB" />

 >       <rollingStyle value="Size" />

 >       <staticLogFileName value="true" />   

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

 >         <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline"
/>

 >       </layout>   

 >     </appender>

 >     <root>

 >       <level value="DEBUG" />

 >       <appender-ref ref="EventLogAppender" />

 >     </root>

 >     <logger name=" com.mypackage.test" >

 >       <level value="DEBUG" />

 >       <appender-ref ref="EventLogAppender" />

 >     </logger>

 >   </log4net>

 > 

 > Michael Schall escribió: 

 > 

 > Are any of the other appenders working(EventViewer, Console)? If not are you configuring
log4net?  I see you have your configuration in your web config file.  We don't do it this
way.   

 > 

 > If the others are working, it has to be in your config file or environment... 

 > 

 > We use external config files and configure it manually during Application_Start in the
global.asax.  Below is a sample of our Web.log4net.config file.  This way we can change logging
without resetting the web site. 

 > 

 > <log4net>

 > 

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

 >         <file value="..\..\log\Regen.log" />

 >         <rollingStyle value="Composite" /> 

 >         <appendToFile value="false" />

 >         <datePattern value="yyyyMMdd" />   

 >         <maximumFileSize value="100MB" />

 >         <maxSizeRollBackups value="-1" /> 

 >         <StaticLogFileName value="false" />

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

 >             <conversionPattern value="%5level [%date] [%thread] %-30.30logger{2}
    %message%newline" />

 >         </layout>

 >     </appender>   

 > 

 >     <appender name="EventLog" type="log4net.Appender.EventLogAppender" >

 >         <applicationName value="Regen" /> 

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

 >             <levelMin value="INFO" />

 >         </filter>

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

 >             <conversionPattern value="%logger %newline %message" />   

 >         </layout>

 >     </appender>

 >     

 >     <root>

 >         <level value="DEBUG" /> 

 >         <appender-ref ref="RollingFile" />   

 >         <appender-ref ref="EventLog" />

 >     </root>

 > 

 > </log4net>

 > 

 > 

 > On 6/27/07, Samuel Rochas < samuel.rochas@iesedu.com> wrote: 

 > > 

 > > Dear Michael, 

 > > 

 > > I have changed my app to write a file using a TextWriter and this is working so
I believe my app has rights to write files. But I still have the log problem, no log file
is created.   

 > > 

 > > Do you have any suggestion on what should I try now?

 > > 

 > > Regards

 > > Samuel

 > > 

 > > Michael Schall escribió: 

 > > 

 > > You don't need to escape them.  Here is my appender declaration...   

 > > 

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

 > >         <file value="C:\Projects\Company_Name\Project_Name\log\web.log" />


 > >         <appendToFile value="true" />

 > >         <maximumFileSize value="100MB" />

 > >         <maxSizeRollBackups value="-1" />

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

 > >             <conversionPattern value="%5level [%date] [%thread] %-30.30logger{2}
   %message%newline" />

 > >         </layout>

 > >     </appender>   

 > > 

 > > 

 > > On 6/22/07, Samuel Rochas <samuel.rochas@iesedu.com > wrote: 

 > > > Dear Michael,

 > > > 

 > > > I run the web server which comes with studio. I am not sure how / where  


 > > > to configure it. I open the IIS tool, and in the "Default web site"

 > > > properties, I setup the directory rights to write. But no change is to see.


 > > > 

 > > > Do you need to escape the '\' characters like you do in Java for the   

 > > > absolute file path like "C:\\path1\\path2\\file.txt"?

 > > > 

 > > > Thank you

 > > > Samuel

 > > > 

 > > > Michael Schall escribió:

 > > > > The user the application is running as has to have rights to write to


 > > > > / create files in the folder where you are logging.  Keep in mind that

 > > > > if you are debugging, that might be a different relative path than if

 > > > > you are running the program directly.  I use an absolute path for my


 > > > > rolling file appenders and they work great.

 > > > >

 > > > > Mike

 > > > 

 > > > 

 > > > 

 > > 

 > > 

 > > 

 > > --

 > > 

 > 

 > 

 > 

 > -- 

 > 

 > 

 > 

 > ________________________________

   

 > 

 > 

 >   

 > 

 >       

 > 

 > Samuel Rochas 

 > International Education Systems (IES) 

 > Technological Resources 

 > Paseo Conde Sepúlveda, 16   40002-Segovia España 

 > Tel: +(34) 921 100 608   g   Fax: +(34) 921 443 592 

 >  samuel.rochas@iesedu.com  g  www.iesedu.com   

 > 

 >  

 > 

 > 

 > 

 > 

   

  

  

 

 

 








Mime
View raw message