In my case I've got a simple listview which contains filepths. When a user double clicks a filepath it does some processing and eventually opens the image. However I need to generate a log file which would output to a text file the date and name of the file executed. What I'm curious to know from you who have had experience with log files is what's an efficient way if generating a log file in this case?
Each time the user clicks a listview item i open the log file and write it...possibly on a seperatr thread in the backgrouns.
While the app is open, each time a user clicks a list view item I append the log data to an array in memory. Then when the app is closed on the closing event I write to the log file the array of logs.
What do you guys recommend or suggest and why?
In general it's recommended to use Log Frameworks.
But if you want to keep thing simple now, you can consider creating a log method like this:
The main idea is writing in file as you said, and you can do it this way for example:
And an example of path could be this:
You can go with Nlog or Elmah logging. They are easy to integrate, configure and use.
You can refer http://blog.ruchir.me/2013/06/error-logging-modules-aspnet-mvc.html blog for more detail.
Main benefit of these tools is they are easy in configuration i.e. you want to maintain log in file or in database. By just few setting in .config file you can switch the method.
LogHelper.cs
You can log the exception and also custom data.
You may have difference log like Payment, Error, User... According to your need you need to create the instance.