Logging from a .dll

  • Thread starter Thread starter John Bailo
  • Start date Start date
J

John Bailo

I have a .exe that calls a .dll

I want to write log messages at various parts of the process in the .exe
and .dll to a common trace/log file.

I set up a method in the .exe to write to the trace file, but to append
basic information like DateTime.Now to each log entry.

How can I get my .dll to write to that same log file?
 
The same way you did it in the EXE, just make sure to be referencing the
correct log assembly and namespace(s) in your DLL.
 
Peter said:
The same way you did it in the EXE, just make sure to be referencing the
correct log assembly and namespace(s) in your DLL.

What do you mean by "log assembly" ?
 
I mean the assembly the contains the log component. For example, whether it
be log4net, or System.Diagnostics, or something else. I was just being
generic and not assuming that you were using the framework classes for your
logging.
 
I see.

But my logging method (which just uses the Trace class) is in the .exe

So how would I write log entry from the .dll using a method in the .exe?
 
You cannot. You will have to move your logging code into a DLL for both the
EXE and DLL to be able to reference it.
 
Not quite true.

The only thing that has to be in the DLL is the interface. As long as the
EXE can create an object that derives from that interface, and can pass that
object to the classes defined in the DLL, then the classes in the DLL can
call the object to perform the logging.


Peter Rilling said:
You cannot. You will have to move your logging code into a DLL for both
the EXE and DLL to be able to reference it.


--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 
Back
Top