Log4net
  1. Log4net
  2. LOG4NET-39

Add pattern to output machine name

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: 1.2.9
    • Component/s: Appenders
    • Labels:
      None

      Description

      It would be very useful in a context of an email appender to be able to specify a "machine name" parameter as part of the layout in order to differentiate between messages coming from dev, stage, and production machines.

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        13m 46s 1 Nicko Cadell 25/Jun/05 04:12
        Nicko Cadell made changes -
        Field Original Value New Value
        Fix Version/s 1.2.9 [ 11092 ]
        Resolution Invalid [ 6 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Hide
        Nicko Cadell added a comment -

        The hostname of the computer is stored in the GlobalContext property 'log4net:HostName'. This property will hold the value of the System.Net.Dns.GetHostName if it is available, otherwise the Environment.MachineName value is used.

        You can output this value using a PatternLayout with the %property

        {log4net:HostName}

        pattern.

        You can also add your own values to the GlobalContext properties e.g.:

        log4net.GlobalContext.Properties["Platform"] = "Stage";

        Show
        Nicko Cadell added a comment - The hostname of the computer is stored in the GlobalContext property 'log4net:HostName'. This property will hold the value of the System.Net.Dns.GetHostName if it is available, otherwise the Environment.MachineName value is used. You can output this value using a PatternLayout with the %property {log4net:HostName} pattern. You can also add your own values to the GlobalContext properties e.g.: log4net.GlobalContext.Properties ["Platform"] = "Stage";
        Hide
        Ron Grabowski added a comment -

        The COMPUTERNAME environment variable seems to contain the machine name on Windows 2003 and Windows XP Professional.

        <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="$

        {COMPUTERNAME}

        %5p %d - %m%n" />
        </layout>

        Show
        Ron Grabowski added a comment - The COMPUTERNAME environment variable seems to contain the machine name on Windows 2003 and Windows XP Professional. <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="$ {COMPUTERNAME} %5p %d - %m%n" /> </layout>
        Hide
        Michael Teper added a comment -

        Would also be useful in a context of a web farm.

        Show
        Michael Teper added a comment - Would also be useful in a context of a web farm.
        Michael Teper created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Michael Teper
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development