My program sends emails. And I'm giving the option to the user to test that it works. This program has 2 parts: A configuration window where the user set the configuration. It's executed with no arguments. And the sending message, that is executed in console with 3 arguments (@to, subject, message).
And I'm using log4net.
This is the code (in my Form). I'm making a call to the same program but with 3 arguments:
var to = inputBox.mailValue;
ProcessStartInfo processInfo = new ProcessStartInfo();
processInfo.FileName = "Mailer.exe";
processInfo.Arguments = to + " Test " + "\"This is a test message sent by Mailer.exe\"";
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
processInfo.RedirectStandardError = true;
Process proc = Process.Start(processInfo);
proc.WaitForExit();
if(proc.ExitCode == 0)
MessageBox.Show("A test message has been sent to " + to + ".\nCheck your inbox & mailerLOG.txt file", "Message sent", MessageBoxButtons.OK, MessageBoxIcon.Information);
else if(proc.ExitCode < 0)
MessageBox.Show("An error ocurred. Check mailerLOG.txt file for more details.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
All works fine, the message is sent, but it doesn't record on my mailerLOG.txt
When a message is sent, I do:
logger.Info("Message with subject <" + mail.Subject + "> has been sent to <" + mail.To + ">");
It neither records if an error ocurred.
What I'm missing?
My log4net config. (which it works properly on the rest of my program)
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<target value="Console.Error" />
<layout type="log4net.Layout.SimpleLayout" />
</appender>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="MailerLOG.txt"/>
<appendToFile value="true"/>
<rollingStyle value="Composite"/>
<datePattern value="yyyyMMdd"/>
<maxSizeRollBackups value="5"/>
<maximumFileSize value="5MB"/>
<staticLogFileName value="true"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date] [%-5level]: %message%newline"/>
</layout>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO"/>
</filter>
</appender>
<root>
<level value="DEBUG"/>
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="RollingFileAppender"/>
</root>
</log4net>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup>
</configuration>