コード例 #1
0
 public void ShouldProperlyEscapeOpenBraces()
 {
     string template = @"Not a \{namespace}";
     CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod());
     string formatted = formatter.FormatCategory(template);
     Assert.AreEqual("Not a {namespace}", formatted);
 }
コード例 #2
0
 public void ShouldReplaceTypeName()
 {
     string template = "Type {type}";
     CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod());
     Assert.AreEqual("Type CategoryFormatterFixture",
                     formatter.FormatCategory(template));
 }
コード例 #3
0
 public void ShouldReplaceMethodName()
 {
     string template = "Method {method}";
     CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod());
     Assert.AreEqual("Method TargetMethod",
                     formatter.FormatCategory(template));
 }
コード例 #4
0
        private TraceLogEntry GetLogEntry(IMethodInvocation input)
        {
            TraceLogEntry     logEntry  = new TraceLogEntry();
            CategoryFormatter formatter = new CategoryFormatter(input.MethodBase);

            foreach (string category in categories)
            {
                logEntry.Categories.Add(formatter.FormatCategory(category));
            }

            logEntry.EventId  = eventId;
            logEntry.Priority = priority;
            logEntry.Severity = severity;
            logEntry.Title    = LogCallHandlerDefaults.Title;

            if (includeParameters)
            {
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                for (int i = 0; i < input.Arguments.Count; ++i)
                {
                    parameters[input.Arguments.GetParameterInfo(i).Name] = input.Arguments[i];
                }

                logEntry.ExtendedProperties = parameters;
            }

            if (includeCallStack)
            {
                logEntry.CallStack = Environment.StackTrace;
            }

            logEntry.TypeName   = input.Target.GetType().FullName;
            logEntry.MethodName = input.MethodBase.Name;
            return(logEntry);
        }
コード例 #5
0
        public void ShouldPropertyEscapeBackslashes()
        {
            string template = @"Here's a method: \\{method}";
            CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod());
            string formatted = formatter.FormatCategory(template);

            Assert.AreEqual(@"Here's a method: \TargetMethod", formatted);
        }
コード例 #6
0
        public void ShouldReplaceAssembly()
        {
            string template = "Assembly {assembly}";
            CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod());
            string formatted = formatter.FormatCategory(template);

            Assert.IsTrue(formatted.StartsWith("Assembly Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.Tests"));
        }
コード例 #7
0
 public void ShouldReplaceNamespace()
 {
     string template = "Namespace {namespace}";
     CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod());
     string formatted = formatter.FormatCategory(template);
     Assert.AreEqual("Namespace Microsoft.Practices.EnterpriseLibrary.Logging.Tests.PolicyInjection",
                     formatted);
 }
コード例 #8
0
 public void ShouldNotReplaceWithoutReplacement()
 {
     string template = "No replacements here";
     CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod());
     Assert.AreEqual(template, formatter.FormatCategory(template));
 }
コード例 #9
0
ファイル: LogCallHandler.cs プロジェクト: Brar/entlib
        private TraceLogEntry GetLogEntry(IMethodInvocation input)
        {
            TraceLogEntry logEntry = new TraceLogEntry();
            CategoryFormatter formatter = new CategoryFormatter(input.MethodBase);
            foreach (string category in categories)
            {
                logEntry.Categories.Add(formatter.FormatCategory(category));
            }

            logEntry.EventId = eventId;
            logEntry.Priority = priority;
            logEntry.Severity = severity;
            logEntry.Title = LogCallHandlerDefaults.Title;

            if (includeParameters)
            {
                Dictionary<string, object> parameters = new Dictionary<string, object>();
                for (int i = 0; i < input.Arguments.Count; ++i)
                {
                    parameters[input.Arguments.GetParameterInfo(i).Name] = input.Arguments[i];
                }

                logEntry.ExtendedProperties = parameters;
            }

            if (includeCallStack)
            {
                logEntry.CallStack = Environment.StackTrace;
            }

            logEntry.TypeName = input.Target.GetType().FullName;
            logEntry.MethodName = input.MethodBase.Name;
            return logEntry;
        }