How to do I save in excel TCP listener message from clients

Sep 22 2018 4:33 AM

I write this code for TCP listener that get message will be stored in text as log file it working in Visual Studio development but I publish no file will be created or not stored messages from client

void server_DataReceived(object sender, SimpleTCP.Message e) { try {             txtStatus.Invoke((MethodInvoker)delegate() {                  e.ReplyLine(string.Format("\r\n CLIENT:>>{0}\r\n", e.MessageString)); CommonControls.writeToLogFile(string.Format("{0}\r\n", e.MessageString)); }); } catch (SocketException e1) {             output = "SocketException: " + e1.ToString(); } }

and the write in text file Hide Copy Code public static void writeToLogFile(string logMessage) { string strLogMessage = string.Empty;

 string strLogFile = System.Configuration.ConfigurationSettings.AppSettings["logFilePath"].ToString(); StreamWriter swLog;          strLogMessage = string.Format("{0}: {1}", DateTime.Now, logMessage); if (!File.Exists(strLogFile)) {             swLog = new StreamWriter(strLogFile); } else {             swLog = File.AppendText(strLogFile); }          swLog.WriteLine(strLogMessage);         swLog.WriteLine();          swLog.Close(); }

As well as i need how to write messages in excel file in published exe file

What I have tried:

I tried in C# Visual Studio by saving logfile when it is BIN folder but how to get when it is Publish EXE file.

When the Visual Studio I run this program that will be work fine the messages will be recorded or stored in text file, but I publish after run the exe file is not store any data.

Thanks in advance.


Answers (1)