Separate log file for each client

R

Rick

Greetings.

I have a program that has a server and multiple clients. Each one
routes its SystemDiagnostics.Trace.WriteLine output to a file. The
target for the writelines is specified in the app.config file. For
example:

<listeners>
<add name="fileLogger"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\Server\logfile.log" />
<remove name="Default" />
</listeners>

The problem is that I would like each of the clients to write to their
own log file. I tried this:

initializeData="~\logfile.log" />

(Each client is run by a different user.) And I tried this:

initializeData="$(USERPROFILE)\logfile.log" />

So both of those were attempts to use one app.config file for multiple
clients.

Another possibility is to have separate app.config files, and point
each client at a different one. By using an environment variable:

set APPCONFIG_PATH=C:\Jim\app.config
client.exe

Or by using some sort of switch on the command line:

client.exe -appconfig C:\Jim\app.config

This must have come up before. What is the usual solution?


Regards,

Rick
 
G

Gregory A. Beamer

(e-mail address removed):

Assumption made: This is a windows app of some sort with multiple users
on the same computer.

(Each client is run by a different user.) And I tried this:

initializeData="$(USERPROFILE)\logfile.log" />

I think you are in the right direction here, but what is causing the
token to be replaced? As it stands, you read this from app.config and
there is nothing automagically filling in the USERPROFILE information.
Another possibility is to have separate app.config files, and point
each client at a different one. By using an environment variable:

set APPCONFIG_PATH=C:\Jim\app.config
client.exe

Or by using some sort of switch on the command line:

client.exe -appconfig C:\Jim\app.config

I think this is an overbloated method.
This must have come up before. What is the usual solution?

If it were me, I would aim in this direction:

1. Tokenize the path in App.Config
2. Add a routine that replaces the token on startup with the user
profile path information
3. Create the directory if it is not there for the user. This need only
happen once, but you check for directory existence each time the app
starts.
4. Supply this information when the logger is started

To make this more maintainable, set up a application variable type of
class (Singleton is a good pattern) that fires up when the app starts
and resolve the path and directory creation when the Singleton is first
called (generally in start up).

If this is a server based app (doubt it), this will not work.

peace and grace,


--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top