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.
| Author |
Messages |
|
Usman Uppal
 |
| 09/27/2005 9:02 PM |
|
Hi, I am a LOG4NET configuration file to log information into a log file and send email to SMTP server. Logging information is successfully getting logged into the log file but email via SMTP Host is not working. Is there anyway to debug why email delivery is not working? I have checked SMTP server, looks like LOG4Net is not even hitting the server, there is no email waiting to be delivered.
I can also ping the SMTP host where my application is installed and can send email via outlook.
Usman
|
|
|
|
|
Ron Grabowski
 |
|
Usman Uppal
 |
| 09/27/2005 9:47 PM |
|
There is no error message in the log file. File is attached.
|
|
|
|
|
Ron Grabowski
 |
| 09/27/2005 9:56 PM |
|
This is a good start. Now let's see your SmtpAppenderFATAL appender node and maybe one or two of the logger nodes that reference it.
|
|
|
|
|
Usman Uppal
 |
| 09/27/2005 10:21 PM |
|
Here is the Config file. Usman
|
|
|
|
|
Ron Grabowski
 |
| 09/28/2005 3:55 PM |
|
I used nDumbster:
http://ndumbster.sourceforge.net/
to setup a mock SMTP server on my system and I was able to see log messages:
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender"> <to value="to@to.com" /> <from value="from@from.com" /> <subject value="SmtpAppender Subject" /> <smtpHost value="127.0.0.1" /> <bufferSize value="1" /> <layout type="log4net.Layout.SimpleLayout" /> <filter type="log4net.Filter.LevelRangeFilter"> <levelMin value="FATAL"/> <levelMax value="FATAL"/> </filter> </appender>
This is what nDumbster processed:
thread-index: AcXEM8in/PUSDjTMRYGRv0fJOIQJAQ== Thread-Topic: SmtpAppender Subject From: <from@from.com> To: <to@to.com> Subject: SmtpAppender Subject Date: Wed, 28 Sep 2005 09:51:53 -0400 Message-ID: <013201c5c433$c8a7e630$640fa8c0@rockinron> MIME-Version: 1.0 Content-Type: text/plain; Content-Transfer-Encoding: 7bit X-Mailer: Microsoft CDO for Exchange 2000 Content-Class: urn:content-classes:message Importance: normal Priority: normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
FATAL - Hello World
--- Usman Uppal <uuppal@salesforce.com> wrote:
> Here is the Config file. > Usman
|
|
|
|
|
Usman Uppal
 |
| 09/28/2005 4:33 PM |
|
Ron, SMTP Appender works on my machine using our internal SMTP host but when I deploy my code on a hosted server (outside of our environment) that is using different SMTP host, it does not work.
Do we need to have Exchange CDO installed on the hosted server? Any other requirements that I should check for?
Thanks for your help.
Usman
|
|
|
|
|
Ron Grabowski
 |
| 09/28/2005 5:33 PM |
|
I don't think you mentioned the part about the application being hosted on a 3rd party server. Have you verified that you can send mail on that server?
using System.Web.Mail; MailMessage mailMessage = new MailMessage(); mailMessage.To = "to@to.com"; mailMessage.From = "from@from.com"; mailMessage.Subject = "Subject"; mailMessage.Body = "Hello World"; SmtpServer.Send(mailMessage);
If you can't send mail, I would extend SmtpAppender and override the SendBuffer method to use something like OpenSMTP:
http://sourceforge.net/projects/opensmtp-net/
The new implementation would be very similiar to the base one:
http://tinyurl.com/a55ec http://cvs.apache.org/viewcvs.cgi/logging-log4net/src/Appender/SmtpAppender.cs?rev=1.9&view=markup
On a slightly unreleated note, here's a screen shot of log4net's SmtpAppender viewed from NLogViewer using nDumbster as a mock SmtpServer (thanks to Jarek for cleaning up my code):
http://www.ronosaurus.com/log4net/nlogviewer_ndumbster_log4net.png
That should be helpful in determining what a good bufferSize property of the SmtpAppender is so it doesn't queue up messages for days then suddenly attempt to send a giant 200mb email.
|
|
|
|
|
Usman Uppal
 |
| 09/28/2005 6:29 PM |
|
Ron, I can send email using your sample code on hosted server.
using System.Web.Mail;
MailMessage mailMessage = new MailMessage();
mailMessage.To = "to@to.com";
mailMessage.From = "from@from.com";
mailMessage.Subject = "Subject";
mailMessage.Body = "Hello World";
SmtpServer.Send(mailMessage);
Any other suggestions?
Thanks,
Usman |
|
|
|
|
Ron Grabowski
 |
| 09/28/2005 6:57 PM |
|
Your had posted this earlier:
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender"> <to value="uuppal@salesforce.com" /> <from value="gordon.chan@logicacmg.com" /> <subject value="ERROR - test Account Process Logging Message" /> <smtpHost value="192.168.1.3" /> <bufferSize value="512" /> <lossy value="false" /> <filter type="log4net.Filter.LevelRangeFilter"> <param name="LevelMin" value="INFO"/> <param name="LevelMax" value="ERROR"/> </filter> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="[%date] %message" /> </layout> </appender>
You are aware that no emails will be sent until 512 messages have been queued up?
Are you able to send mail using these more general settings?
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender"> <to value="uuppal@salesforce.com" /> <from value="gordon.chan@logicacmg.com" /> <subject value="ERROR - test Account Process Logging Message" /> <smtpHost value="192.168.1.3" /> <bufferSize value="1" /> <layout type="log4net.Layout.SimpleLayout" /> </appender>
|
|
|
|
|
Usman Uppal
 |
| 09/28/2005 7:12 PM |
|
Ron, Yes setting buffer to 1 works on the third party server. I am getting one email per line of information logging.
Why buffer size of 512 works from my pc and not the 3rd party server? What should be appropriate buffer size? usman
|
|
|
|
|
Ron Grabowski
 |
| 09/28/2005 7:42 PM |
|
I don't know why it would work with 1 but not with 512. At least we know the SmtpAppender is working correctly. Is there a message body size limit imposed by your server? Why not run more tests to get a better idea of what the bufferSize fails on:
1: works 10: ??? 50: ??? 200: ??? 350: ??? 512: doesn't work
If the bufferSize fails to delivery 350 messages I would output 350 message to a text file then read those messages in and try manually sending the mail:
using System.Web.Mail; MailMessage mailMessage = new MailMessage(); mailMessage.To = "to@to.com"; mailMessage.From = "from@from.com"; mailMessage.Subject = "Subject"; using (StreamReader sr = new StreamReader("350_log_messages.txt")) { mailMessage.Body = sr.ReadToEnd(); } SmtpServer.Send(mailMessage);
If that works and 512_log_messages.txt works I'm afraid I've run out of ideas :(
Another non-related comment...It would be interesting if someone wrote a SmtpAppender that would send the logging events as an attachment:
<appender name="AttachmentSmtpAppender" type="..."> <to value="..." /> <from value="..." /> <subject value="..." /> <body value="See attached file(s) for logs" /> <smtpHost value="..." /> <bufferSize value="512" /> <layout type="log4net.Layout.SimpleLayout" /> <attachedFile value="DEBUG.txt"> <filter type="log4net.Filter.LevelMatchFilter"> <levelToMatch value="DEBUG" /> </filter> </attachedFile> <attachedFile value="INFO.txt"> <filter type="log4net.Filter.LevelMatchFilter"> <levelToMatch value="INFO" /> </filter> </attachedFile> </appender>
That would send a single message with a user supplied body that would contain two attachments: DEBUG.txt containing only DEBUG messages and INFO.txt containing only INFO messages.
|
|
|
|
|
Richman Michael
 |
| 09/28/2005 8:40 PM |
|
I've noticed that one one of our servers, an appender might not work until we change the config file.
I've noticed this on the smtp appender, and it doesn't fail consistenly one one buffer size, it stops working sometimes, and any change to the config file, including to the bufferSize seems to reset something.
Michael
|
|
|
|
|
Ron Grabowski
 |
| 09/28/2005 9:27 PM |
|
Did you configure log4net with ConfigureAndWatch or just Configure?
The built-in System.Web.Mail.SmtpServer.Send method has a void return type. Unless I'm mistaken, it does not record its interactions with the mail server. OpenSMTP probably supports this. I know the AspNetEmail email component does:
http://www.aspnetemail.com/
If you're paranoid about mail not being sent, you should probably invest in a component that has logging:
EmailMessage msg = new EmailMessage("Mail1.MyCompany.com"); msg.FromAddress = "me@MyCompany.com"; msg.AddTo("you@YourCompany.com", "Billy Bob"); msg.Subject = "Daily Newsletter"; msg.Body = "Here is our daily newsletter....."; msg.Logging = true; if (msg.Send() == false) { LogLog.Error(String.Format("Unable to send mail. Log: {0}", msg.GetLog()), msg.LastException()); }
|
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|