../../_images/sitetitle3.png

Static Meta Data

Introduction to Static Meta Data

Static Meta Data is meta data that is added to every log event generated through the system.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="nulog" type="NuLog.Configuration.ConfigurationSectionHandler, NuLog" />
    </configSections>
    <nulog>
        <!-- ... -->
        <metaData>
            <add key="Server" value="Web42B" />
            <add key="Env" value="Prod" />
            <add key="Release" value="1.2.42" />
        </metaData>
        <!-- ... -->
    </nulog>
</configuration>

Static Meta Data is useful for including information about the environment the logger is running on, helping to identify problems in your infrastructure. The benefit of including static meta data this way, is that these values can be transformed during a standard CI/CD process, being automatically updated by your favorite CI/CD tool, such as Octopus Deploy.

Updated Layout to Include Static Meta Data

Once you have your static meta data in place, you could include it in a custom layout for your targets:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="nulog" type="NuLog.Configuration.ConfigurationSectionHandler, NuLog" />
    </configSections>
    <nulog>
        <!-- ... -->
        <targets>
            <target name="file" type="NuLog.Targets.TextFileTarget" path="app.log"
                    layout="${DateTime:'{0:MM/dd/yyyy hh:mm:ss.fff}'} | ${Release}-${Server}-${Env} | ${Tags} | ${Message}${?Exception:'\r\n{0}'}\r\n" />
        </targets>
        <!-- ... -->
    </nulog>
</configuration>

With the static meta data from the previous section, and this layout, ${Release}-${Server}-${Env} would be rendered as 1.2.42-Web42B-Prod.

For more information about layouts, see Layouts/Log Format (up next).