Currently my application is using log4net to log errors, the web.config for this is as followed:
<log4net> <appender name="FileAppender" type="log4net.Appender.RollingFileAppender"> <file type="log4net.Util.PatternString" value="../../logs/gateway_%date{yyyyMMdd}.log" /> <appendToFile value="true" /> <rollingStyle value="Date" /> <datePattern value="yyyyMMdd" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] – %message%newline" /> </layout> </appender> <root> <level value="DEBUG" /> <appender-ref ref="RollingLogFileAppenderOutput" /> </root> </log4net>
However, the client now wants each error to be emailled to them.
What is the easiest way to do this, can you do it within the web.config file?
Often, this error message has the same cause as the Mailbox not found message. However, occasionally there's a problem with the recipient's email account that will resolve itself over time. Try this fix: Wait a short time and try to send your message again. If that fails, check the recipient's email address for typos.
On the Message tab, in the Tags group, select Follow Up, and then select Add Reminder. Select Flag for Recipients. To send a flag without a reminder alert, clear the Reminder check box. Select the Flag for Me check box, and if you want, the Reminder check box.
In the web version of Outlook, click the gear icon, then Automatic Replies. If you don't see the Automatic Replies button, you might need some extra help to get started. Go to aka.ms/autoreply to learn more. In the Automatic Replies window, select Send automatic replies.
How does the error checker work? When you've finished editing your email, click the Check & Preview button and select “Check for errors” from the drop-down menu. Click on an error from the list to resolve it. Errors are listed in order of where they appear in your email template from top to bottom.
You should use SmtpAppender
<appender name="SmtpAppender" type="log4net.Appender.SmtpAppender"> <to value="[email protected]" /> <from value="[email protected]" /> <subject value="test logging message" /> <smtpHost value="SMTPServer.domain.com" /> <bufferSize value="512" /> <lossy value="true" /> <evaluator type="log4net.Core.LevelEvaluator"> <threshold value="WARN"/> </evaluator> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%newline%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%newline%newline" /> </layout> </appender> <logger name="ErrorLogger"> <level value="Error" /> <appender-ref ref="FileAppender" /> </logger> <logger name="EmailLogger"> <level value="Error" /> <appender-ref ref="SmtpAppender" /> </logger>
In order to send emails only for an specific error you could do something like this
try { // your logic } catch (MySpecificException ex) { // I only send emails for exception of type MySpecificException LogManager.GetLogger("EmailLogger").Error(ex); } catch (Exception ex) { // Just log to a file for the rest LogManager.GetLogger("ErrorLogger").Error(ex); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With