You really should consider using something like log4net
to do the logging. It can be downloaded here. And the configuration is dead simple. In your app.config
file you can add the section
tag to the configSections
tag and then add the log4net
configuration tag.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="EventLogAppender" />
</root>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<threshold value="DEBUG" />
<applicationName value="Lantic YCS WebServer" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="(%-5level %date{hh}:%date{mm}:%date{ss} [%thread] %logger [%property{NDC}] ) %message %n" />
</layout>
</appender>
</log4net>
</configuration>
Then in your code you just need to initialize it, so at the top of every class file drop in this line:
private static readonly ILog log = LogManager.GetLogger(typeof(Global));
allowing you to say something like:
log.Error(...);
but also, when the application first starts, don't forget to run this line:
log4net.Config.XmlConfigurator.Configure();
Now, to address a more interesting concern that I personally have. You stated that you're building a folder monitor. You really don't want, or need, to build that. Please simply use the FileSystemWatcher
that's already available. It's extremely efficient, and filterable as well, so you get the messages you want.