![]() |
|
[C#] Adding text to .txt file in webserver - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] Adding text to .txt file in webserver (/showthread.php?tid=6070540) |
Adding text to .txt file in webserver - Formula 1 - Apr 23, 2020 Hello, I made a logs.txt to see how many times user connects to my application, i saved it in .txt file (On my pc) But i want to do the same thing to a file (log.txt) on webserver Code /*RE: Adding text to .txt file in webserver - gigajew - Apr 23, 2020 What kind of server side software are you running? FTP? Php? RE: Adding text to .txt file in webserver - Shadow_Cloud - Apr 23, 2020 As per another post I would strongly advise log4net for this. What you are doing here isn't thread safe and could easily result in exceptions. Code class ProgramHave a look here > https://stackify.com/log4net-guide-dotnet-logging/ RE: Adding text to .txt file in webserver - Formula 1 - Apr 23, 2020 (Apr 23, 2020 08:12 AM)gigajew Wrote: What kind of server side software are you running? FTP brother. RE: Adding text to .txt file in webserver - gigajew - Apr 23, 2020 (Apr 23, 2020 09:29 AM)uberhacker Wrote: FTP brother. Here you go https://docs.microsoft.com/en-us/dotnet/framework/network-programming/how-to-upload-files-with-ftp RE: Adding text to .txt file in webserver - notahackerman - Apr 23, 2020 (Apr 23, 2020 07:15 AM)uberhacker Wrote: Hello, pm me: hackerman#0001 RE: Adding text to .txt file in webserver - ОЯВІТ - Apr 23, 2020 you're going to want to download the existing logs.txt from your webserver, append the new line and re-upload it making sure to overwrite the existing file. If you don't want to hardcode your FTP creds into your application you should look into something like this https://www.php.net/manual/en/function.file-put-contents.php Where your application will make a single web request and the server will handle logging and writing to the file. This is safer and will also help if your application has lots of users. lmk if you need any help with this RE: Adding text to .txt file in webserver - Shadow_Cloud - Apr 24, 2020 (Apr 23, 2020 08:01 PM)ОЯВІТ Wrote: you're going to want to download the existing logs.txt from your webserver, append the new line and re-upload it making sure to overwrite the existing file. I wouldn't take the first approach, as this file grows it will become more and more bandwidth intensive. If you get to the point where that file is 2MB, you are downloading it, appending on the client, then uploading the 2MB again. And this will just get worse, plus the app has the details to connect which is already a code smell. The second option is much better, but it's still important to make sure that when the server writes to disk its doing so in a thread safe manner. |