Friday, May 18, 2012
 
The best way to analyze your logs! Minimize
 Log4Net Mail archive   

The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.

Subject: Using log4Net from my web service (.net 2.0, C#); nothing happens
Prev Next
You are not authorized to post a reply.

Author Messages
Sriram Ranganathan

10/30/2008 11:22 AM  


My web service is using C# and .Net 2.0

When a "handled" exception is thrown during the web service call, the
service should return normally but should log some information so some admin
chappie can look at it later.

So I thought of usnig log4net but don't know how to. After checking on the
net, it seemed easy enough:

1: This is In my web.config file of the web service:

*************************************************************
<?xml version="1.0"?>

<configuration>

<configSections>

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

</configSections>

<log4net>

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

<file value="chuckchuck.log" />

<appendToFile value="true" />

<maximumFileSize value="100KB" />

<maxSizeRollBackups value="2" />

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

<conversionPattern value="%level %thread %logger - %message%newline" />

</layout>

</appender>

<root>

<level value="DEBUG" />

<appender-ref ref="RollingFile" />

</root>

</log4net>


<appSettings/>

<connectionStrings/>

<system.web>

<compilation debug="true"/>

<authentication mode="Windows"/>


</system.web>

</configuration>

2. This is in the class where I have to do the logging:

**********************************************************************

 using System;

using log4net;

using log4net.Config;

public class CalculationNotPossibleException : Exception

{

protected static readonly ILog log =
LogManager.GetLogger(typeof(CalculationNotPossibleException));

public CalculationNotPossibleException()

{

}

private String userMessage;

public String UserMessage

{

get { return userMessage; }

set { userMessage = value; }

}

public void logInput(CalculationInput p_calculationInput)

{

log.Debug("Sriram says DEBUG - this text will be in log file");

log.Info("Sriram says INFO - this text will be in log file");

}

}

********************************************************************

3. When my web service is invoked, I know for a fact that the above code
(log.debug .....) is executed. I know the code control comes there, so I
expect there to be a log file called chuckchuck.log created and the above
lines to be printed into that file.

But that doesn't happen.

I don't get any errors (even in eventviewer) from log4net but there is no
log file called chuckchuck.log in my entire system ... I did a search for
all files with this name.

Some people might say I have to create an appender in the log4j section of
the web.config file for the name "CalculationNotPossibleException" which is
my class name that is doing the logging. But the way I see it, the root is
supposed to handle it all, so it oughta work.

 In my application, this is the only place I have to log anything. So there
is no other related code anywhere at all.

So what am I missing?

Request - for those people givnig ideas, if you are saying "put the log4j
thingies in a separate config file" etc .... any comments like this ...
please tell me details such as where (location) I am supposed to save the
new config file and how my web service is supposed to pick up the location
of this config file ... etc etc. I.e. - please give precise comments with as
much detail as possible .... I would really appreciate it.

Wherever possible, please give me the code to do whatever I am missing,
whether it be in my C# file or in my web.config or any other config u might
ask me to make.

Thanks and much appreciation,

Sriram Ranganathan


--
View this message in context: http://www.nabble.com/Using-log4Net-from-my-web-service-%28.net-2.0%2C-C-%29--nothing-happens-tp20244011p20244011.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Dean Fiala

10/30/2008 2:48 PM  

This is likely a permissions error.  You need to grant the ASP.NET user (or
NETWORK SERVICE user for Win2k3 or higher) write permissions on the folder
where you want to write the log file to.  The default is to only allow the
user to read files, not write them.

Sriram Ranganathan

10/30/2008 3:00 PM  


The only change I made was this:

I included a Global.asax file to my web service, and wrote the following
line of code in the start method. That is it ... the code worked and the
logging happened.

***********************************************

void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        log4net.Config.XmlConfigurator.Configure();
    }

***********************************************

Thanks everyone, for listening!

Cheers

Sriram Ranganathan
--
View this message in context: http://www.nabble.com/Using-log4Net-from-my-web-service-%28.net-2.0%2C-C-%29--nothing-happens-tp20244011p20247590.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

You are not authorized to post a reply.
Forums > Log4Net > Log4Net Mail archive > Using log4Net from my web service (.net 2.0, C#); nothing happens



ActiveForums 3.7

 

 

 

 

 

 

 

 

Log4Net Dashboard

Log analysis and monitoring made easy!

Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

You can download a free developer version.

  

Check it out!

On the demonstration site you can try it  with live data.demo.l4ndash.com - Try Log4Net Dashboard with live data

The mail archive is a copy of all the mail sent to the mail address: log4net-user@logging.apache.org, organized as a forum.

If you would like to participate in the mail list, send a mail to log4net-user-subscribe@logging.apache.org.

More information about the mailing list is available on: http://logging.apache.org/log4net/support.html

 

A complete topic list is available and can be viewed here (warning, it takes some time to load)

 

Copyright 2005-2008 by FaktNet AS Terms Of Use Privacy Statement