You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
As far as I am aware, the @ simply indicates a verbatim string literal. It is not going to control where the file is written.
Your code works for me in a copy of MT4 installed outside \Program Files, and crashes if MT4 is installed inside \Program Files.
If I run MT4 from a location such as C:\MyMT4, i.e. such that the executable is C:\MyMT4\terminal.exe, then the file ClientMessage.txt is created at C:\MyMT4\ClientMessage.txt. This is obviously going to cause problems if MT4 is inside a protected area of disk such as \Program Files.
If I change your code as follows ...
{
try
{
using (StreamWriter writer = new StreamWriter(@"ClientMessage.txt", true))
{
writer.WriteLine(line);
}
}
catch (Exception e)
{
System.Diagnostics.Trace.WriteLine(e.Message);
}
}
... then the exception which is logged when I use the DLL from a copy of MT4 within Program Files is, very unsurprisingly, as follows:
THANKS JC!!
Where is the exception written to? I went looking into the event viewer and couldn't find it.
To everyone, I apologize. I was wrong. It WAS where the file was getting written that was making it crash.
Where is the exception written to? I went looking into the event viewer and couldn't find it.
The usual way of monitoring the output of Trace.WriteLine is DbgView: https://technet.microsoft.com/en-us/sysinternals/debugview.aspx
Thanks.
I thought there was a way to write the exception in the catch segment to the event viewer.
I thought there was a way to write the exception in the catch segment to the event viewer.
DbgView is usually preferred for ad-hoc debug logging, but if you want to write to the Windows event logs then you can try things such as this.