How do I get multiple process to log to the same file?
2010-02-03 19:03
519 查看
How do I get multiple process to log to the same file?
By default the FileAppender holds an exclusive write lock on the log file while it is logging. This prevents other processes from writing to the file. The FileAppender can be configured to use a different locking model, MinimalLock, that only acquires the write lock while a log is being written. This allows multiple processes to interleave writes to the same file, albeit with a loss in performance. See the FileAppender config examples for an example MinimalLock configuration.While the MinimalLock model may be used to interleave writes to a single file it may not be the optimal solution, especially when logging from multiple machines. Alternatively you may have one or more processes log to RemotingAppenders. Using the RemoteLoggingServerPlugin (or IRemoteLoggingSink) a process can receive all the events and log them to a single log file.
http://logging.apache.org/log4net/release/faq.html
FileAppender
For full details see the SDK Reference entry: log4net.Appender.FileAppender.The following example shows how to configure the FileAppender to write messages to a file. The file specified is log-file.txt. The file will be appended to rather than overwritten each time the logging process starts.
<appender name="FileAppender" type="log4net.Appender.FileAppender"> <file value="log-file.txt" /> <appendToFile value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> </layout> </appender>
This example shows how to configure the file name to write to using an environment variable TMP. The encoding to use to write to the file is also specified.
<appender name="FileAppender" type="log4net.Appender.FileAppender"> <file value="${TMP}/log-file.txt" /> <appendToFile value="true" /> <encoding value="unicodeFFFE" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> </layout> </appender>
This example shows how to configure the appender to use the minimal locking model that allows multiple processes to write to the same file.
<appender name="FileAppender" type="log4net.Appender.FileAppender"> <file value="${TMP}/log-file.txt" /> <appendToFile value="true" /> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> </layout> </appender>
http://logging.apache.org/log4net/release/config-examples.html#fileappender
相关文章推荐
- HOWTO get multiple value from the same name checkbox elements or radiobution elements
- How to get files to show up in the Process Monitor/Report Repository
- How to get the "connection string" from web.config file
- Java How to get the PID from a process?
- the diary of how to get a random word within a file
- How to download Xcode 4 / 5 / 6 / 7 and get the DMG file?
- How to process the Properties file!
- How to get the file's icon using C++ - 用C++如何获取文件的图标
- How to load the specified mscordacwks.dll for managed debugging when multiple .NET runtime are loaded in one process
- How to delete the log file of log4j dynamically
- How_do_I_use_the_same_pkg_file_for_debug_and_release_builds(转)
- How to get the password text in a text with password property from another process using C++ - 用C++如何从不同进程获取密码框文本
- How to get the size of file in C++ - 在C++中如何获取文件的大小
- Multiple process create and delete the same name file conflict
- How to get a high quality system in the developing process?
- How to get the data from a cell when I click on the GridButtonColumn of the same row
- How To Get Application Path,And How To Get The Path's Directory,File Name,And Type Info(如何得到运行程序的路径,以及如何得到路径的文件夹,文件名,以及类型等等信息)
- How can I force Python's file.write() to use the same newline format in Windows as in Linux (“\r\n”
- How to Get the Length of File in C
- How to get the MD5 checksum for a file: md5sum, digest, csum, fciv