c# - How do I detect if I'm running in the console -


is there simple way have code library automatically detect if it's being called console application or windows application? i'd library not report windows event log if it's being called console window, instead report console window. if however, it's not being run within console window, should report windows event log.

i thought requiring logging component passed log target, neat if automatically handle these 2 targets natively. don't yet require extensive log4net, indeed, if becomes necessary provide support log database/file , other yet unknown logging targets, may recommend such solution. though, having component auto-detect environment , log console or event log according environment plenty.

architecturally, passing logging context library component right choice. library doesn't, , indeed shouldn't, know context environment it's being run in.

because want support these 2 special cases natively within library, i'd suggest unified approach.

  1. go ahead , create more generalized logging entry point/knob caller controls.
  2. create separate entry point/knob automatically sets generalized 1 cases want automatically support.

even seems complicated based on description, though. have considered using appropriate tracelisteners in diagnostics collection, console app adds appropriate tracelistener output console , non-console app adds appropriate eventlog tracelistener output windows event log? has added advantage of working built-in .net logging support without assuming external dependencies (e.g., log4net).


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -