c# - Enterprise Library Logging Block Get Configuration From web.config -


i've web api application. in solution of application, there several projects.

and api's in 1 single project. , there 1 project business layer.

we want write 1 logging class containing relevant methods in business layer project , going use "enterprise library logging block".

what correct procedure related configuration web.config in class of business layer project.

thanks in advance.

if configuration contained in web.config , business layer assembly executes in same appdomain web api application thing need bootstrap blocks using (in case sounds logging).

you @ application startup (e.g. app_start):

logger.setlogwriter(new logwriterfactory().create()); 

in approach business layer use static facade logger.write write logentries.

a better approach create small wrapper around logwriter bootstrap block , expose logwriter use in business layer (and anywhere needs logging). bit more friendly dependency injection since it's easy register in container , can passed in dependency.

public class logger {     private lazy<logwriter> logwriter = new lazy<logwriter>(() =>         {             logwriterfactory factory = new logwriterfactory();             return factory.create();         });      public logwriter logwriter     {         { return logwriter.value; }     }             } 

since internally logwriter singleton , want bootstrap once make custom logger class singleton. (if don't care having instance make logger entirely static.)


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -