Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>an additional answer which might help somebody<br> following Steve's suggestion I changed my logging service implementation to have a constructor that accepts a type i.e. the type argument to supply in the Log method as specified in the ILogger interface</p> <pre><code>public class MyLogging_Service : IMyLogging_Service { private Type _declaringType; private ILog _log; private ILog Log { get { return _log; } } public MyLogging_Service(Type p_Val) { _declaringType = p_Val; _log = LogManager.GetLogger(p_Val); } public void LogInfo(string p_Msg) { Log.Logger.Log(_declaringType, Level.Info, p_Msg, null); } ... } </code></pre> <p>actual usage</p> <pre><code>public class Service1 : IService1 { // declared as a property IMyLogging_Service MyLoggingService { get; set; } } </code></pre> <p>before that I used StructureMap to fill this property automatically using setter injection <br>see <a href="http://codebetter.com/jeremymiller/2008/10/09/setter-injection-in-structuremap-2-5/" rel="nofollow">link</a></p> <p>in my dependency injection bootstrapper i used the following statement</p> <pre><code>FillAllPropertiesOfType&lt;IMyLogging_Service&gt;().TheDefault.Is .ConstructedBy(context =&gt; new MyLogging_Service(context.ParentType)); </code></pre> <p>to recap <br>1. created a class to implement logging using a constructor that accepts a type to use for specifying the callerStackBoundaryDeclaringType argument in the Log method implementation <br>2. created a logging service property for a class that needs to have logging functionality <br>3. included code in the dependency injection bootstrapper to fill the property with the parent type using the context StructureMap variable</p> <p>btw in cases in your code where DI is not necessary then you can write code like this <br></p> <pre><code>new MyLogging_Service(this.GetType()) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload