Ejemplo n.º 1
0
        public void Logging()
        {
            const string message       = "Error Message";
            const string messageFormat = "Message Format: message: {0}, exception: {1}";
            var          ex            = new Exception();

            var log = new SerilogLogger(GetType());

            Assert.IsNotNull(log);

            log.Debug(message);
            log.Debug(message, ex);
            log.DebugFormat(messageFormat, message, ex.Message);
            log.Debug(ex, messageFormat, messageFormat, ex);

            log.Error(message);
            log.Error(message, ex);
            log.ErrorFormat(messageFormat, message, ex.Message);
            log.Error(ex, messageFormat, messageFormat, ex);

            log.Fatal(message);
            log.Fatal(message, ex);
            log.FatalFormat(messageFormat, message, ex.Message);
            log.Fatal(ex, messageFormat, messageFormat, ex);

            log.Info(message);
            log.Info(message, ex);
            log.InfoFormat(messageFormat, message, ex.Message);
            log.Info(ex, messageFormat, messageFormat, ex);

            log.Warn(message);
            log.Warn(message, ex);
            log.WarnFormat(messageFormat, message, ex.Message);
            log.Warn(ex, messageFormat, messageFormat, ex);
        }
Ejemplo n.º 2
0
        public void SendResetPassword(UmbracoHelper umbraco, string email, string guid)
        {
            try
            {
                //logger.Info<EmailHelper>("Send Reset: {0} {1}", email, guid);

                string from     = Current.Configs.Settings().Content.NotificationEmailAddress;
                string baseURL  = HttpContext.Current.Request.Url.AbsoluteUri.Replace(HttpContext.Current.Request.Url.AbsolutePath, string.Empty);
                var    resetUrl = baseURL + umbraco.GetDictionaryValue("ForumAuthConstants.ResetUrl", "/reset").TrimEnd('/') + "/?resetGUID=" + guid;

                var messageBody = umbraco.GetDictionaryValue("Forum.ResetBody", $@"<h2>Password Reset</h2>
            <p>we have received a request to reset your password</p>
            <p><a href='{resetUrl}'>Reset your password</a></p>");

                MailMessage message = new MailMessage(from, email)
                {
                    Subject    = umbraco.GetDictionaryValue("Forum.ResetSubject", "Reset your password"),
                    IsBodyHtml = true,
                    Body       = messageBody
                };

                SmtpClient client = new SmtpClient();
                client.Send(message);
            }
            catch (Exception ex)
            {
                logger.Error <ForumEmailHelper>("Error {0}", ex.Message);
            }
        }
Ejemplo n.º 3
0
        public void Error_LambdaMessage()
        {
            // Prepare
            const string message = "Simple Message";

            logger.Setup(l => l.Write(
                             LogEventLevel.Error, message, null))
            .Verifiable();
            log = new SerilogLogger(logger.Object);

            // Act
            log.Error(message);

            // Assert
            logger.VerifyAll();
        }
Ejemplo n.º 4
0
        public void Error_WritesException_IntoSerilog()
        {
            // arrange
            var fixture   = new Fixture();
            var exception = fixture.Create <Exception>();
            var serilog   = A.Fake <global::Serilog.ILogger>();

            // act
            var sut = new SerilogLogger(serilog);

            sut.Error(exception);

            // assert
            A.CallTo(() => serilog.Error(exception, exception.Message))
            .MustHaveHappened();
        }
Ejemplo n.º 5
0
        public void Error_MessageWithException()
        {
            // Prepare
            const string message = "Exception occurred";
            var          ex      = new Exception(message);

            logger.Setup(l => l.Write(
                             LogEventLevel.Error, ex, message, null))
            .Verifiable();
            log = new SerilogLogger(logger.Object);

            // Act
            log.Error(message, ex);

            // Assert
            logger.VerifyAll();
        }