design - What's the point of a logging facade? -
there bunch of different logging libraries choose from, each own set of quirks , advantages. (.net examples: log4net, system.diagnostics.tracesource, nlog, etc.)
the natural inclination abstract away quirks , use logging facade. (examples: castle.services.logging, common.logging, simple logging facade) way, if given logging framework you're using goes stale, or different 1 comes vogue, can swap out implementation , leave code untouched.
but there multiple logging facades choose from. given answer many disparate logging implementations abstraction, why not use logging facade facade? if sounds ridiculous, makes more ridiculous original logging facade? makes 1 layer of abstraction on top of logging framework magic number?
i speak perspective of using abstraction insulate application code particular logging framework. there other factors can affect one's choice of logging framework or one's choice of (and requirements for) abstraction.
i have spent lot of time evaluating various logging frameworks third party logging abstractions.
some people feel there value in insulating application code specific logging framework. find many posts here on this , this , this(and there more) logging discussed , many people take matter of course logging framework should wrapped/abstracted.
obviously, allows not tied specific framework. important? ever switch out logging framework? well, there plenty of people either don't mention wrapping or recommend against it. if @ of examples of logging framework wrapping code has been posted here, can see many examples of why @ least people should not wrap logging framework!
if had started project recently, might have examined logging frameworks and, perhaps, narrowed down 2 finalists: log4net , nlog. each has arguments in favor. log4net favorite, favorite of have expressed opinion. nlog provides similar capabilities. judged popularity, log4net might clear choice. based on capabilities, seem similar. based on "recent activity" (as indicated checkins source code repostories blog activity or lack thereor), nlog clear choice. if had pick year ago, might go log4net since "safe" choice. not clear when nlog release. in year since, nlog has gone through pretty signifcant development cycle, releasing beta version few days ago.
which choose year ago? choose now? 1 better choice then? 1 better choice now?
one thing abstraction gets ability put off decision of 1 choose (you don't have choose ever, although want if plan deliver logging framework product). can test drive 1 , other , feel how work application, team, in environment. using common.logging or slf allows start writing code now, coding logging interface/api, , getting logging code in place. if believe interface/api provided abstraction sufficient work (and, why wouldn't since same interface/api provided log4net , nlog), there not danger in using abstraction. go through development cycle, might find 1 framework or other better suits needs. having coded abstraction, free make choice @ point, until time product goes out door.
you might thinking, in of mind, possibly write logging library scratch. again, if believe interface/api of log4net and/or nlog sufficient, might implement logging library similar api. if believe that, might reason use abstraction. again, can start writing code (for product, not logging library) today, logging other logging framework until such time "from scratch" logging library ready. maybe want use system.diagnostics.tracesource , ukadc.diagnostics (to output formatting capabilities similar log4net or nlog) can "better" integration logging microsoft has implemented in of platforms using tracesources. pretty easy write "logger" in terms of tracesources , write abstraction plug common.logging or slf. (if interface/api sufficient, write "logger" in terms of abstraction library's interface , not have write additional abstraction layer).
with such persuasive arguments these, why ever not use abstraction? ha ha, kidding!
if abstraction good, should write own or use existing one? if write 1 on own, have write it. how 1 this? well, might define interface , wrap 1 framework (be careful , wrap correctly!). later, if decide want switch, wrap framework. if careful, don't have change application code, except maybe place create underlying framework's objects. maybe good. have avoided dependency on third party abstraction "small" price of implementing single wrapper on single framework. however, there cost. until have written abstraction cannot write lot of application code has logging in it, unless have strategy changing on abstraction. becomes more difficult test drive 2 or more frameworks decide works better your. each framework want "try" requires wrap job. if want switch among frameworks (at least during development cycle), have work make easy. third party frameworks provide out of box.
wow! i'm sold! give me logging abstraction, or give me death!
are logging abstractions gravy? there downside? can't great, can they?
well, always, when "buying" or when getting free, available. logging abstractions no different. neither common.logging nor slf expose @ least 1 important set of capabilities of log4net/nlog - logging context capabilities (gdc, mdc, ndc). these can key getting adequate information logged , formatted enable value your. slf not provide tracesource abstraction. not provide isxxxenabled functions. common.logging provides tracesource abstraction. castle.logging expose gdc/mdc/ndc log4net , nlog. provides tracesource abstraction. castle's tracesource abstraction enhances tracesource logging providing "hierarchical" naming capability, similar provided log4net , nlog. looks pretty cool!
also, these projects opensource of 1 form or another. so, depending on abstraction, developers might have more or less of vested interest in keeping date , adding new features. common.logging has been through few versions , used, afaik, in spring.net. seems reasonbly active, @ least historically. castle.logging used in castle framework. so, apparently have "real" customers , getting "real world" usage, drive more feature implementation. slf, far can tell, not used part of "real" development platform, hard tell how exercised.
it not clear roadmap these platforms. common.logging has upcoming features listed on website, not clear indication when available. website says "june", of year? how mailing list monitored? slf, how codeplex monitored? priority of these "free" projects rate compared developers' paying jobs? can afford third party abstraction implement feature need? receptive if implement , submit consideration included in product?
on plus side, of source of these abstractions available, assume responsibility , make fixes or add enhancements which, without having go through time , energy of creating abstraction scratch. common.logging want log4net/nlog gdc/mdc/ndc? castle's implementation , add common.logging. voila! logging abstraction contains 100% of log4net/nlog logging api. prefer slf wish had isxxxenabled? not work implement that. go ahead , tack on gdc/mdc/ndc while @ it. castle? (i'm not familiar it, not sure how easy use outside of castle, if matters) careful, haven't used it, looking @ source on git, looks nlog logger abstraction might not retain call site info.
is ethical take parts of multiple open source projects , combining them make 1 "super" project (for own or company's use)? bad take common.logging , augment castle's gdc/mdc/ndc implementation? don't know. i'll let else answer that.
i'm finished...
some third party logging abstractions provide other capabilities. might use library implemented in terms of, log4net. might not want use log4net, or @ least might not want tied it. common.logging (and maybe slf) makes relatively easy capture log4net logging messages , reroute them through abstraction captured in abstraction's underlying logging framework's logging stream. slf might provide similar. of course, might able similar existing logging frameworks, either out of box or writing custom log4net appender, nlog target, or system.diagnostics tracelistener. these features have not bubbled high in particular evaluation of whether or not use third party logging abstraction on project because interested in abstraction aspect.
so, stand? think there value in keeping application code insulated specific logging framework. me, common.logging looks solid choice of abstraction, although important features missing (gdc/mdc/ndc) , not silverlight compatible. great of features became available soon. comfortable implementing gdc/mdc/ndc if have to. making silverlight compatible take more effort, because not particularly experienced c#/.net/silverlight. until issues ironed out, able write plenty of application code common.logging in place. can spend our time developing our application rather developing yet logging library or abstraction library. if end having add missing features ourselves, well, have had lot of if had implementing logging library or abstraction library ourselves.
Comments
Post a Comment