I am writing event data to a log file in an asp.net httphandler by using the File.AppendAllText method. I am concerned with what will happen when multiple requests are received simultaneously. Does AppendAllText lock the file it's writing to?
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to store image outside of the website's ro
- 'System.Threading.ThreadAbortException' in
- Request.PathInfo issues and XSS attacks
- How to dynamically load partial view Via jquery aj
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- how do I log requests and responses for debugging
- “Dynamic operations can only be performed in homog
- What is the best way to create a lock from a web a
no, you should have a static lock object guarding the log-file write, e.g.
You can use My.Log to write to log files.
Edit: If you use the FileLogTraceListener, that listener is thread-safe.
Doing this also allows you to control and configure the logging through the web.config file.
I recommend using the
TextWriterTraceListener
instead of trying to manage this your self.It is very simple to setup and use:
And then to log something:
It is very simple to use and also there are many different types of listeners for SQL, Event Log, text file, etc. So you won't have to adjust your code if you want to change out the listener.