`
yangyou230
  • 浏览: 1649626 次
文章分类
社区版块
存档分类

How do I get multiple process to log to the same file?

 
阅读更多

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
分享到:
评论

相关推荐

    UE(官方下载)

    Have you ever needed to combine multiple files into a single destination (output) file? You can use a combination of a script and tool to create a single file from multiple files. Sum Column/Selection...

    Foundations for Analytics with Python O-Reilly-2016-Clinton W. Brownley

    Finally, the chapter explains how to get your computer to read a text file, read multiple text files, and write to a CSV-formatted output file. These are important techniques for accessing input data...

    端口查看工具

    of cports.exe, and CurrPorts will automatically use it to get the country/city information for every remote IP address. * Version 2.02: o CurrPorts now displays a simple error message if it fails ...

    微软内部资料-SQL性能优化3

    In this scenario, since T1 believes it locks the entire table, it might inadvertently make changes to the same row that T2 thought it has locked exclusively. In a multigranular locking environment, ...

    JSP Simple Examples

    In this program we are going to know how the server determines whether the password entered by the user is correct or not. This whole process is controlled on the server side. Multiple forms in jsp ...

    微软内部资料-SQL性能优化5

    The IAM allows SQL Server to do efficient prefetching of the table’s extents, but every row still must be examined. General Index Structure All SQL Server Indexes Are Organized As B-Trees ...

    au3反编译源码

    To copy text or to enlarge the log window double click on it. Supported Obfuscators: 'Jos van der Zande AutoIt3 Source Obfuscator v1.0.14 [June 16, 2007]' , 'Jos van der Zande AutoIt3 Source ...

    ImpREC 1.7c

    - Added an IRC log to explain how to use it (Greetings to LaBBa) - Tracers - Error codes updated for the Tracers Level2 and 3 - Plugin Tracer - Redesigned interface for good reasons (See ) - ...

    VB编程资源大全(英文源码 其它)

    6 , chunks.zip This will open a file and read it in "Chunks" of a selected file.&lt;END&gt;&lt;br&gt;7 , logging.zip This is a bas that will log installation procedures so the file can be removed later....

    ICS delphixe10源码版

    to ease support of multiple versions of Delphi and platforms, and to ease location of similar sample projects. Please don't install V8 over an existing V7 installation, it will be a mess of old and ...

    VB编程资源大全(英文源码 控制)

    If you try it in VB, you will get a runtime error, but this code shows you how to do it. Gilbert says&lt;END&gt;&lt;br&gt;51 , ledbulb.zip This is a first for this author. Its an OCX which represents a ...

    Visual C++ 编程资源大全(英文源码 其它)

    45.zip Get VersionInfo from resource file 从资源文件中得到程序的版本信息(1)(6KB)&lt;END&gt;&lt;br&gt;46,dynip.zip A IP Poster for people with dynamic IP addresses(18KB)&lt;END&gt;&lt;br&gt;47,cliptalk.zip An ...

    DebuggingWithGDB 6.8-2008

    4.8 Killing the Child Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.9 Debugging Programs with Multiple Threads . . . . . . . . . . . . . . . . . . 4.10 Debugging ...

    MySQL 5.6 Reference Manual

    1.14. Apache log4j Version 1.2.9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

    pro_apache_third_edition..pdf

    Get Someone Else to Do It.............................................................................36 Summary...........................................................................................

Global site tag (gtag.js) - Google Analytics