Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jason Espin 368 posts 1335 karma points
    Oct 27, 2014 @ 14:30
    Jason Espin
    0

    Log4Net custom code failing to write to log

    Hi all,

    I have created a new Surface controller for use with my Umbraco 7.1.8 installation. My code is as follows:

    public class EnquiryController : SurfaceController
        {
            ILog Log = LogManager.GetLogger(
                MethodBase.GetCurrentMethod().DeclaringType
            );
    
            [HttpPost]
            public ActionResult Submit(EnquiryModel model)
            {
                if (!ModelState.IsValid)
                    return CurrentUmbracoPage();
    
                // Create a regular expression to remove script tags
                Regex regex = new Regex(@"<script(.+?)*</script>");
                string request = regex.Replace(model.Message, string.Empty);
                request = request + "<br/><br/>" + "Phone: " + model.Telephone + "<br/><br/>" + "Email: " + model.Email;
    
                MailMessage message = new MailMessage();
                message.From = new MailAddress(model.Email);
                message.To.Add(new MailAddress("[email protected]"));
                message.Subject = "New Website Enquiry - " + model.Name;
                message.Body = request;
    
                SmtpClient client = new SmtpClient();
    
                try
                {
                    client.Send(message);
                    TempData["success"] = true;
                }
                catch (Exception ex)
                {
                    TempData["error"] = true;
                    Log.Debug("Custom Error - " + ex.Message);
                    return CurrentUmbracoPage();
                }
    
                return RedirectToCurrentUmbracoPage();
    
            }
    
        }
    

    My problem is my code fails to send the Email and simply performs the CurrentUmbracoPage() method call.

    To counteract this and find out what the issue is I have attempted to log the Exception that is generated using Log4Net however this does not appear to be working as nothing is written to the standard Umbraco log.

    This is all occuring on a live server. I have published my development code using Visual Studio 2013 and then uploaded this published site to the server via FTP ensuring that the correct SMTP detals are entered into the Web.Config.

    The one thing that concerns me and could be a cause of this issue is that this publish process seems to omit the /Controllers and /Models folders from my solution despite the actually being a part of the project. Is this an issue or are these compiled in .dlls?

    To me it seems rather odd that the controllers folder is omitted and could potentially explain why the Email is not being sent..

Please Sign in or register to post replies

Write your reply to:

Draft