Within my strategy I use streamwriter to write various strings to a text file as and when they happen, to help with debugging and development. These are written within OnBarUpdate (for 10sec series & tick series) and OnExecutionUpdate. I've been experiencing occasional/intermittent streamwriter conflicts (file already in use) that causes my strategy to shut down (sometimes with open positions). I can't see any issues with the code and from research on this forum it seems like streamwriter is generally prone to issues. I'm considering the following approach to resolve:
Rather than writing every update to a file, I store them in a String, with each update appending the new updates to the same string. Then only on each 10sec OnBarUpdate I write to the text file and reset the string to empty. This way, there's only one use of streamwriter every 10secs so no risk of conflict, however the downside is that the string itself could end up becoming large.
Questions please:
1. Is there a maximum length of the string?
2. Are there any alternative approaches I should consider beyond string?
Thanks in advance for any guidance
ChainsawDR

Comment