Why is XmlConfiguratorAttribute preferred? That doesn't make sense to me. If
you use logging from multiple assemblies, then using "Configure" is the only
way to ensure the correct order (init before usage) - isn't it?

-- 
Werner


Yuriy Taraday wrote:
> 
> When whole application needs logging, it's preferable to use
> XmlConfiguratorAttribute instead of Configure method.
> Again, it looks cleaner when you put your logging settings to web.config
> file.
> To do so, you must add this line to configSections:
>     <section name="log4net"
> type="log4net.Config.Log4NetConfigurationSectionHandler, log4net,
> Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821" />
> (may be changing Version/PuplicKeyToken if you use not 1.2.10 official
> release) And put <log4net> tag into <configuration>.
> 
> On Wed, Apr 28, 2010 at 10:43 AM, ITemplate <itempl...@hotmail.com> wrote:
>>
>> Oh forgot - be sure to initialize the configuration (one time, in
>> Application_Start as mabra suggested for example) like this:
>> XmlConfigurator.Configure();
>>
>> --
>> Werner
>>
>>
>> ITemplate wrote:
>>>
>>> No because that would produce a compile error - the problem, as I read
>>> it,
>>> is that the program works alright but the logfile just isnt created.
>>>
>>> Anyways, it could be a security issue. A web application would probably
>>> not have rights to write to that directory you have specified. Try to
>>> set
>>> the log file like this: <file value="sample.log" /> . Then look in the
>>> directory where your application runs.
>>>
>>> That said it should definately not be nescessary to specify the location
>>> of the log4net configuration. Putting it in web.config should be enough
>>> -
>>> it could indicate a problem that is of an entirely different matter.
>>>
>>> --
>>> Werner
>>>
>>>
>>> mabra wrote:
>>>>
>>>>
>>>> Hi !
>>>>
>>>> To me, it looks like, you forgot to create a logger, befor you log ....
>>>> !??
>>>> Missing:
>>>>
>>>>      ILog log =  log4net.LogManager.GetLogger(typeof(yourType));
>>>>
>>>> In my web scenarios, I call it ether in the constructor or use
>>>> a "global" variable, which I initilize like shown above.
>>>> You my call it in "Application_Start(...)"
>>>>
>>>> Hope, this helps.
>>>>
>>>> br++mabra
>>>>
>>>>
>>>> -----Original Message-----
>>>> From: Dotnet_user [mailto:dotnet_use...@yahoo.com]
>>>> Sent: Tuesday, April 27, 2010 5:17 PM
>>>> To: log4net-user@logging.apache.org
>>>> Subject: Problem logging exceptions
>>>>
>>>>
>>>> Hello everyone,
>>>>
>>>> I'm using log4net to log my exceptions. The configuration settings look
>>>> like
>>>> this:
>>>>
>>>> <?xml version="1.0" encoding="utf-8" ?>
>>>>
>>>> <configuration>
>>>>
>>>> <configSections>
>>>>
>>>> <section name="log4net"
>>>> type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
>>>>
>>>> </configSections>
>>>>
>>>> <log4net debug="false">
>>>>
>>>> <appender name="RollingLogFileAppender"
>>>> type="log4net.Appender.RollingFileAppender">
>>>>
>>>> <file value="C:\Logs\sample.log" />
>>>>
>>>> <appendToFile value="true"/>
>>>>
>>>> <rollingStyle value="Size"/>
>>>>
>>>> <maxSizeRollBackups value="10"/>
>>>>
>>>> <maximumFileSize value="10MB"/>
>>>>
>>>> <staticLogFileName value="true"/>
>>>>
>>>> <layout type="log4net.Layout.PatternLayout">
>>>>
>>>> <conversionPattern value="%-5level %date %logger.%method[line %line] -
>>>> %message%newline"/>
>>>>
>>>> </layout>
>>>>
>>>> </appender>
>>>>
>>>> <root>
>>>>
>>>> <level value="INFO"/>
>>>>
>>>> <appender-ref ref="RollingLogFileAppender"/>
>>>>
>>>> </root>
>>>>
>>>> </log4net>
>>>>
>>>> </configuration>
>>>>
>>>> I started out by adding this configuration to web.config, but I got an
>>>> error
>>>> (VS studio could not find a schema for log4net-"Could not find schema
>>>> information for the element log4net"). So I followed this link
>>>> (http://stackoverflow.com/questions/174430/log4net-could-not-find-schema-inf
>>>> ormation-messages)
>>>> and configured my settings in a separate xml file and added the
>>>> following
>>>> line of code in my AssemblyInfo.cs:
>>>>
>>>> [assembly: log4net.Config.XmlConfigurator(ConfigFile = "xmlfile.xml",
>>>> Watch
>>>> = true)]
>>>>
>>>> And in the actual code, I placed this line:
>>>>
>>>> public void CreateUser(String username, String password)
>>>>
>>>> {
>>>>
>>>> try
>>>>
>>>> {
>>>>
>>>> log.Info("Inside createuser");
>>>>
>>>> //code for creating user
>>>>
>>>> }
>>>>
>>>> catch(exception e)
>>>>
>>>> {
>>>>
>>>> log.Info("something happened in create user", e);
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>> The problem is that the log file is not being created. Can anybody tell
>>>> me
>>>> what I'm doing wrong here?
>>>>
>>>> Any suggestions/inputs will be very helpful.
>>>>
>>>>
>>>>
>>>> Thank you all in advance.
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/Problem-logging-exceptions-tp28378261p28378261.html
>>>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/Problem-logging-exceptions-tp28378261p28385317.html
>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Problem-logging-exceptions-tp28378261p28399035.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Reply via email to