How to custom the logging information with the TagAttribute Matching Rule

Jun 15, 2011 at 3:02 PM

Hi All,

Now I use the policy injection and get the log informations with the Tag Attribute Matching Rules. I get the informations successfully.

1、How to get the log information with the custom format?

2、It seems I get the log informations duplicate once I invoke the method.

The follow is my sample:

ITest test=PolicyInjection.Create<TestObj,ITest>();

test.RunTest();// With Tag Attribute.

Timestamp: 2011/6/15 14:44:37
Message: 
Category: General
Priority: -1
EventId: 0
Severity: Information
Title:Call Logging
Machine: ********
App Domain: PolicyInjectLoggingApplication.vshost.exe
ProcessId: 7408
Process Name: F:\Coder\EnterpriseLibrary\EFSolution\PolicyInjectLoggingApplication\bin\Debug\PolicyInjectLoggingApplication.vshost.exe
Thread Name: 
Win32 ThreadId:3680
Extended Properties: 

I get the information duplicate.

Any help will be appriciate.

Best Regards.

 

David

Jun 16, 2011 at 1:28 AM

Hi,

Anyone can give some advices?

Thanks.

Jun 16, 2011 at 2:48 AM

Hi,

Can you post your complete code here so we can further analyze the issue.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 16, 2011 at 2:08 PM
Edited Jun 16, 2011 at 2:09 PM

Hi,

I had log the information with the default format. What should I do if I want the information contain my class name.

 

Timestamp: 2011/6/15 14:44:37
Message: 
Category: General
Priority: -1
EventId: 0
Severity: Information
Title:Call Logging
Machine: ********
App Domain: PolicyInjectLoggingApplication.vshost.exe
ProcessId: 7408
Process Name: F:\Coder\EnterpriseLibrary\EFSolution\PolicyInjectLoggingApplication\bin\Debug\PolicyInjectLoggingApplication.vshost.exe
Thread Name: 
Win32 ThreadId:3680
Extended Properties:  //The Default 

ADD

CustomClassName: MyClass

Jun 17, 2011 at 5:55 AM
Edited Jun 17, 2011 at 6:08 AM

Hi,

It may look simple but you need to extend your Logging Call Handler. You also need to extend the default log entry so that it can hold the class name. Finally, create a custom TextFormatter that implements the ILogFormatter and add the class name to the Format method. In your custom call handler your code may look something like this:

public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) 

     {  
	CustomLogEntry myCustomLog = new CustomLogEntry();
         ...
	myCustomLog.ClassName = input.Target.GetType().Name; 
	logWriter.Write(myCustomLog);       
         return getNext()(input, getNext); 
    } 

You can refer to the links below on how to extend logging and call handler:
http://msdn.microsoft.com/en-us/library/ff664603(v=pandp.50).aspx
http://blog.technicallyworks.com/2010/10/aop-with-enterprise-library-policy.html

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jun 21, 2011 at 7:01 AM

Thank you for your advice.