public void CanDeserializeFormattedCustomEntry()
        {
            CustomLogEntry entry = new CustomLogEntry();

            entry.TimeStamp    = DateTime.MaxValue;
            entry.Title        = "My custom message title";
            entry.Message      = "My custom message body";
            entry.Categories   = new List <string>(new string[] { "CustomFormattedCategory", "OtherCategory" });
            entry.AcmeCoField1 = "apple";
            entry.AcmeCoField2 = "orange";
            entry.AcmeCoField3 = "lemon";

            string         serializedLogEntryText = new BinaryLogFormatter().Format(entry);
            CustomLogEntry deserializedEntry      =
                (CustomLogEntry)BinaryLogFormatter.Deserialize(serializedLogEntryText);

            Assert.IsNotNull(deserializedEntry);
            Assert.IsFalse(ReferenceEquals(entry, deserializedEntry));
            Assert.AreEqual(entry.Categories.Count, deserializedEntry.Categories.Count);
            foreach (string category in entry.Categories)
            {
                Assert.IsTrue(deserializedEntry.Categories.Contains(category));
            }
            Assert.AreEqual(entry.Message, deserializedEntry.Message);
            Assert.AreEqual(entry.Title, deserializedEntry.Title);
            Assert.AreEqual(entry.AcmeCoField1, deserializedEntry.AcmeCoField1);
            Assert.AreEqual(entry.AcmeCoField2, deserializedEntry.AcmeCoField2);
            Assert.AreEqual(entry.AcmeCoField3, deserializedEntry.AcmeCoField3);
        }
Example #2
0
        public void FormatsPropertyToken()
        {
            TextFormatter  formatter = new TextFormatter("Reflected Property Value: {property(MyProperty)}");
            CustomLogEntry entry     = new CustomLogEntry();

            string actual = formatter.Format(entry);

            Assert.AreEqual("Reflected Property Value: myPropertyValue", actual);
        }
Example #3
0
 public void LogCustom(CustomLogEntry logEntry)
 {
     using (IUnitOfWork unit = pManager.UnitOfWorkFactory.CreateIsolatedUnitOfWork(false, true, null, null, null, null))
     {
         IRepository <CustomLogEntry> repo = unit.GetRepository <CustomLogEntry>();
         repo.Put(logEntry);
         unit.Commit();
     }
 }
Example #4
0
        public static void LogCustom(string message)
        {
            //if (!AppConfiguration.IsLoggingEnable || !AppConfiguration.IsCustomLoggingEnable)
            //    return;
            CustomLogEntry logEntry = new CustomLogEntry();

            logEntry.LogType    = LogType.Custom;
            logEntry.Desription = message;

            LogCustom(logEntry);
        }
Example #5
0
        public static void LogCustom(CustomLogEntry logEntry)
        {
            //if (!AppConfiguration.IsLoggingEnable || !AppConfiguration.IsCustomLoggingEnable)
            //    return;
            ILogger logger = create(logEntry.LogType);

            logEntry = (CustomLogEntry)prepareLogEntry(logEntry);
            logEntry = (CustomLogEntry)refineLogEntry(logEntry);
            CustomLogDelegate dlgt = new CustomLogDelegate(logger.LogCustom);
            IAsyncResult      ar   = dlgt.BeginInvoke(logEntry, null, null);
        }
Example #6
0
        public void FormatReflectedPropertyTokenFunctionPropertyFoundAndNullValue()
        {
            CustomLogEntry entry = new CustomLogEntry();

            ILogFormatter formatter = new TextFormatter("Reflected Property Value: {property(MyPropertyThatReturnsNull)}");
            string        actual    = formatter.Format(entry);

            string expected = "Reflected Property Value: ";

            Assert.AreEqual(expected, actual);
        }
        public void FormatCustomTokenFunction()
        {
            CustomLogEntry entry = new CustomLogEntry();

            ILogFormatter formatter = new CustomTextFormatter("Acme custom token template: [[AcmeDBLookup{value1}]]");
            string        actual    = formatter.Format(entry);

            string expected = "Acme custom token template: 1234";

            Assert.AreEqual(expected, actual);
        }
Example #8
0
        public void FormatReflectedPropertyTokenFunctionPropertyNotFound()
        {
            CustomLogEntry entry = new CustomLogEntry();

            ILogFormatter formatter = new TextFormatter("Reflected Property Value: {property(PropertyNotFound)}");
            string        actual    = formatter.Format(entry);

            string expected = string.Concat("Reflected Property Value: ", string.Format(Resources.ReflectedPropertyTokenNotFound, "PropertyNotFound"));

            Assert.AreEqual(expected, actual);
        }
Example #9
0
        public void TimeStampTokenLocalTimeWithFormat()
        {
            CustomLogEntry entry = new CustomLogEntry();

            entry.TimeStamp = DateTime.MaxValue;
            ILogFormatter formatter = new TextFormatter("TimeStamp: {timestamp(local:F)}");
            string        actual    = formatter.Format(entry);

            string expected = string.Concat("TimeStamp: " + DateTime.MaxValue.ToLocalTime().ToString("F", CultureInfo.CurrentCulture));

            Assert.AreEqual(expected, actual);
        }
Example #10
0
        public void TimeStampTokenUtcTime()
        {
            CustomLogEntry entry = new CustomLogEntry();

            entry.TimeStamp = DateTime.MaxValue;

            ILogFormatter formatter = new TextFormatter("TimeStamp: {timestamp}");
            string        actual    = formatter.Format(entry);

            string expected = string.Concat("TimeStamp: " + DateTime.MaxValue.ToString());

            Assert.AreEqual(expected, actual);
        }
Example #11
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            CustomLogEntry log = new CustomLogEntry();

            log.Message = txtLog.Text;
            log.Categories.Add(Category.General);
            log.Priority = Priority.Normal;
            log.MyStuff  = string.Format("This is my stuff {0}", txtLog.Text);

            ExceptionLogWriter.Write(new NullReferenceException());

            writer.Write(log);
        }
Example #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <param name="traceEventType"></param>
        /// <param name="customData"></param>
        /// <param name="Title"></param>
        /// <returns></returns>
        private void InsertarCustomLogEntryScheduler(LogWriter logWriter, string message, TraceEventType traceEventType, string customData, string title)
        {
            var customLogEntry = new CustomLogEntry()
            {
                Categories = new string[] { "Scheduler Execution Error" },
                Message    = message,
                Severity   = traceEventType,
                CustomData = customData,
                Title      = title
            };

            logWriter.Write(customLogEntry);
        }
Example #13
0
        public void LogCustom(string message)
        {
            CustomLogEntry logEntry = new CustomLogEntry();

            logEntry.LogType    = LogType.Custom;
            logEntry.Desription = message;

            using (IUnitOfWork unit = pManager.UnitOfWorkFactory.CreateIsolatedUnitOfWork(false, true, null, null, null, null))
            {
                IRepository <CustomLogEntry> repo = unit.GetRepository <CustomLogEntry>();
                repo.Put(logEntry);
                unit.Commit();
            }
        }
Example #14
0
        public override string Format(LogEntry log)
        {
            CustomLogEntry customEntry = (CustomLogEntry)log;

            base.TemplateBuilder.Replace("{field1}", customEntry.AcmeCoField1);
            base.TemplateBuilder.Replace("{field2}", customEntry.AcmeCoField2);
            base.TemplateBuilder.Replace("{field3}", customEntry.AcmeCoField3);

            CustomToken custom = new CustomToken();

            custom.Format(base.TemplateBuilder, log);

            return(base.Format(log));
        }
Example #15
0
        public void DictionaryTokenCanHandleInternalParenthesisAsLongAsTheyAreNotFollowedByACurlyBracket()
        {
            TextFormatter  formatter         = new TextFormatter("{dictionary(({key})-{value} - )}");
            CustomLogEntry entry             = new CustomLogEntry();
            Dictionary <string, object> hash = new Dictionary <string, object>();

            hash["key1"]             = "value1";
            hash["key2"]             = "value2";
            entry.ExtendedProperties = hash;

            string actual = formatter.Format(entry);

            Assert.AreEqual("(key1)-value1 - (key2)-value2 - ", actual);
        }
Example #16
0
        protected override void SendMessageCore(LogEntry logEntry)
        {
            if (logEntry is CustomLogEntry)
            {
                //handle a CustomMessageInfo object with extra metadata
                CustomLogEntry customLog = (CustomLogEntry)logEntry;

                CustomLogEntrySink.Field1 = customLog.AcmeCoField1;
                CustomLogEntrySink.Field2 = customLog.AcmeCoField2;
                CustomLogEntrySink.Field3 = customLog.AcmeCoField3;
            }

            CustomLogEntrySink.fullMessage = FormatEntry(logEntry);
            CustomLogEntrySink.Body        = logEntry.Message;
            CustomLogEntrySink.EventID     = logEntry.EventId;
            CustomLogEntrySink.Category    = logEntry.Category;
        }
Example #17
0
        public void SendCustomLogEntryViaMsmq()
        {
            CustomLogEntry log = new CustomLogEntry();

            log.TimeStamp    = DateTime.MaxValue;
            log.Title        = "My custom message title";
            log.Message      = "My custom message body";
            log.Categories   = new string[] { "CustomFormattedCategory" };
            log.AcmeCoField1 = "apple";
            log.AcmeCoField2 = "orange";
            log.AcmeCoField3 = "lemon";
            clientSource.TraceData(TraceEventType.Information, 1, log);
            msmqDistributor.CheckForMessages();
            Assert.IsFalse(MockTraceListener.LastEntry == log);
            Assert.AreEqual(MockTraceListener.LastEntry.Message, log.Message);
            Assert.AreEqual(((CustomLogEntry)MockTraceListener.LastEntry).AcmeCoField1, log.AcmeCoField1);
            Assert.AreEqual(((CustomLogEntry)MockTraceListener.LastEntry).AcmeCoField2, log.AcmeCoField2);
            Assert.AreEqual(((CustomLogEntry)MockTraceListener.LastEntry).AcmeCoField3, log.AcmeCoField3);
        }
        public void SendCustomLogEntryViaMsmq()
        {
            CustomLogEntry log = new CustomLogEntry();

            log.TimeStamp    = DateTime.MaxValue;
            log.Title        = "My custom message title";
            log.Message      = "My custom message body";
            log.Category     = "CustomFormattedCategory";
            log.AcmeCoField1 = "apple";
            log.AcmeCoField2 = "orange";
            log.AcmeCoField3 = "lemon";

            msmq.SendLog(log);

            msmqDistributor.CheckForMessages();

            string expected = "Timestamp: 12/31/9999 11:59:59 PM\r\nTitle: My custom message title\r\n\r\nAcme Field1: apple\r\nAcme Field2: orange\r\nAcme Field3: lemon\r\n\r\nMessage: My custom message body";
            string actual   = CommonUtil.GetLastEventLogEntryCustom();

            Assert.AreEqual(expected, actual);
        }
        public void AddTransformerParametersTest()
        {
            IExtraDataTransformer extraFieldsProvider = new SampleLogDataProvider();

            DatabaseTraceListener_Accessor target = new DatabaseTraceListener_Accessor(
                storedProcedureName, logConnectionStringName, null, extraFieldsProvider);

            object data = new CustomLogEntry { JobId = 12345, RepId = 54321 };
            IDbCommand command = new SqlCommand();
            //MockRepository mocks = new MockRepository();

            //IDbCommand command = mocks.StrictMock<IDbCommand>();
            //IDataParameterCollection parameters = mocks.StrictMock<IDataParameterCollection>();

            //Expect.Call(command.Parameters).Return(parameters);

            //Expect.Call(command.Parameters.Add(target.factory.CreateParameter(
            //                    (p) => { p.DbType = DbType.String; p.Value = 12345; p.ParameterName = "JobId"; })));
            //Expect.Call(command.Parameters).Return(parameters);
            //Expect.Call(command.Parameters.Add(target.factory.CreateParameter(
            //        (p) => { p.DbType = DbType.String; p.Value = 54321; p.ParameterName = "RepId"; })));
            //mocks.ReplayAll();

            target.AddTransformerParameters(data, command);

            //mocks.VerifyAll();
            IDataParameter jobParam = command.Parameters["JobId"] as IDataParameter;
            Assert.IsNotNull(jobParam);
            Assert.IsNotNull(jobParam.Value);
            Assert.AreEqual<string>(jobParam.Value.ToString(), "12345");

            IDataParameter repParam = command.Parameters["RepId"] as IDataParameter;
            Assert.IsNotNull(repParam);
            Assert.IsNotNull(repParam.Value);
            Assert.AreEqual<string>(repParam.Value.ToString(), "54321");
        }
Example #20
0
 public void LogCustom(CustomLogEntry logEntry)
 {
     throw new NotImplementedException();
 }
		public void CanDeserializeFormattedCustomEntry()
		{
			CustomLogEntry entry = new CustomLogEntry();
			entry.TimeStamp = DateTime.MaxValue;
			entry.Title = "My custom message title";
			entry.Message = "My custom message body";
			entry.Categories = new List<string>(new string[] { "CustomFormattedCategory", "OtherCategory" });
			entry.AcmeCoField1 = "apple";
			entry.AcmeCoField2 = "orange";
			entry.AcmeCoField3 = "lemon";

			string serializedLogEntryText = new BinaryLogFormatter().Format(entry);
			CustomLogEntry deserializedEntry =
				(CustomLogEntry)BinaryLogFormatter.Deserialize(serializedLogEntryText);

			Assert.IsNotNull(deserializedEntry);
			Assert.IsFalse(object.ReferenceEquals(entry, deserializedEntry));
			Assert.AreEqual(entry.Categories.Count, deserializedEntry.Categories.Count);
			foreach (string category in entry.Categories)
			{
				Assert.IsTrue(deserializedEntry.Categories.Contains(category));
			}
			Assert.AreEqual(entry.Message, deserializedEntry.Message);
			Assert.AreEqual(entry.Title, deserializedEntry.Title);
			Assert.AreEqual(entry.AcmeCoField1, deserializedEntry.AcmeCoField1);
			Assert.AreEqual(entry.AcmeCoField2, deserializedEntry.AcmeCoField2);
			Assert.AreEqual(entry.AcmeCoField3, deserializedEntry.AcmeCoField3);
		}