2

I have an .net assembly at C#. I have both: binary and source which has no logger, for example. All I need is to insert property which will be initialised specific logger. Then I need to introduce logger invoker in all methods. The first way - is manually write property and their invokes. And the second way - is to write another class\method (I suppose in the same assembly) which will do it automatically.

Is it possible? Any suggestions?

I think it is possible, cause it was one of the questions at the interview. But there is no proof that this is possible, and they wanted to hear "no, do this manually".

1

2 Answers 2

2

This is what we call in architectural terms a 'cross cutting concern'. Logging is something that straddles many aspects of an application.

There are features to take care of it in the Microsoft Enterprise Library. The part you want is the Policy Injection library. You can then specify, in the config, methods to match (based on method name/structure) and a function to be called. In this way you can include logging as a proper cross-cutting concern of your app, rather than something which must be manually coded into every method.

Sign up to request clarification or add additional context in comments.

Comments

0

It is not possible to alter the execution of a method without altering the source code and recompiling. You could write a wrapper class that would expose all classes and methods which would first call your logger and then the methods, but that's not what they asked.

So the answer to their question is 1. is possible, 2. isn't possible, and if you would have to add logging support, you would need to add it to each method manually.

1 Comment

It is possible to do this without adding it to each method manually using the Policy Injection section of the Microsoft Enterprise Library: msdn.microsoft.com/en-us/library/ff647463.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.