advice on dotnet architecture please

  • Thread starter Thread starter SoxFan44
  • Start date Start date
S

SoxFan44

I'm pertty new to designing software, so I have what's probably a very
simple question. I'm designing a Windows Forms application in C#. I have a
class LogMessage that will hold a single log message. I am creating a
Logger class where the constructor will take in a LogMessage and log it to a
file and update a Windows Form.

My question is, should Logger be a static class? And in what file/function
should I create the Logger instance so that it's accessible from all forms
and other classes? Thanks for the help!
 
First, you will want to create a separate Class Library project for your
LogMessage class, so that it can be used in any Solution of another project,
and when you're finished, add that project to your application's Solution.

Create the LogMessage class in such a way that it does not need to know
anything about the client using it. This can be done by exposing properties
and methods that a client class can work with.

In order for your Form to be updated from the LogMessage class, you will
want to add Events to the LogMessage class that the client class can
subscribe to.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Shooter
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.
 
SoxFan44 said:
I'm pertty new to designing software, so I have what's probably a very
simple question. I'm designing a Windows Forms application in C#. I have a
class LogMessage that will hold a single log message. I am creating a
Logger class where the constructor will take in a LogMessage and log it to a
file and update a Windows Form.

My question is, should Logger be a static class? And in what file/function
should I create the Logger instance so that it's accessible from all forms
and other classes? Thanks for the help!

No need to re-invent the wheel anyways - get Log4Net, a
de-facto-standard logging solution. But yes, your logs should
generally be a static/singleton/global/whateveryouwant to call it. The
log is a single, physical logfile, and every class must write to that
log, so just having it accessible by all (in it's own project) is
probably ideal.
 
Back
Top