Logging

The ice.NET Platform provides access to a logging system and emits logging information itself.

Using the Logging functionality

To emit log messages from your own application logic, use the PDTec.IceNet.Core.Runtime.ILogger interface and the PDTec.IceNet.Sdk.Utils.LoggingUtils factory class as follows:

public class MyClass
{
    internal static readonly ILogger s_pLog = LoggingUtils.GetLogger("my.app");

    public void DoSomething()
    {
        s_pLog.Info("Now I am doing something.");
        
        //...
    }
}

Configuring the Logging functionality

As a default, ice.NET uses the log4net Logging framework up to Release 4.6. Since the default will be switched to the internal logging framework of .NET (system.diagnostics) in the following ice.NET versions it is recommended to configure this explicitly in your application right now:

<ice.net>
    <logging factory="PDTec.IceNet.Sdk.Utils.TraceLoggerFactory,PDTec.IceNet.Sdk" />
</ice.net>

Upon availability of ice.NET 5.0 this entry will be unnecessary.

The logging output can be configured by the standard system.diagnostics settings in the application .config file. In the following example all logging messages go to the DebugOut listener that is implemented by DebugTraceListener and the security-related messages go to a file-based listener SecurityLog that is implemented by LogFileTraceListener.

<system.diagnostics>
    <trace autoflush="true" />
    <sources>
        <source name="*" switchValue="Verbose">
            <listeners>
                <clear />
                <add name="DebugOut" />
            </listeners>
        </source>
        <source name="ic.sc.ad" switchValue="Information">
            <listeners>
                <clear />
                <add name="SecurityLog" />
            </listeners>
        </source>
    </sources>
    <sharedListeners>
        <add name="DebugOut" type="PDTec.IceNet.Sdk.Utils.DebugTraceListener,PDTec.IceNet.Sdk" />
        <add name="RollingFile" type="PDTec.IceNet.Sdk.Utils.LogFileTraceListener,PDTec.IceNet.Sdk" initializeData="file=..\__logs\icestudio_webui.log, rolling=size|10|1MB" />
        <add name="SecurityLog" type="PDTec.IceNet.Sdk.Utils.LogFileTraceListener,PDTec.IceNet.Sdk" initializeData="file=[CommonApplicationData]\icestudio_webui_security.log" />
    </sharedListeners>
</system.diagnostics>

The configuration of sources follows a hierarchical pattern that is based on names. A source configuration matches a ILogger instance if the ILogger name starts with the source name. The most complete match determines which source configuration is used for a specific ILogger instance.

Trace Listeners

Any system.diagnostics-cpmpatible trace listeners can be used. In addition to this, ice.NET provides a collection of useful alternative trace listeners:

DebugTraceListener

The PDTec.IceNet.Sdk.Utils.DebugTraceListener sends all input to the OutputDebugString Windows API. Therefore it is possible to watch the log messages in tools such as Sysinternals DebugView. For retrieving messages from IIS-based applications that run under special process identities, it is required that DebugView is run as Administrator.

LogFileTraceListener

As its name suggests, the PDTec.IceNet.Sdk.Utils.LogFileTraceListener writes log messages to a file. It can be configured to support a rolling file pattern with the initializeData attribute:

initializeData="file=..\__logs\icestudio_webui.log, rolling=size|10|1MB"

  • rolling=size|20|10MB -- the file is rolled every 10 MB, 20 historic files are kept
  • rolling=date|20 -- the file is rolled every day, 20 historic files are kept

Filename Parameters

The LogFileTraceListener filename can be extended by dynamic placeholder variables. Three types of placeholders are supported:

  • Environment variables encoded according to the %PARAMETER% pattern.
  • Builtin folder variables: |Desktop|, |ApplicationData|, |LocalApplicationData|, |CommonApplicationData|, |Temp|
  • ice.NET 6.0: the {!} placeholder that is replaced by the command line parameter /logfileparam:PARAMETER.

ice.NET Logging Hierarchy

The messages emitted by the ice.NET Platform are grouped under the logging prefix ic. The following table provides an overview:

- ic          ice.NET

- ic.md       Model
- ic.md.fi    File Implementation
- ic.md.ir    Implementation Registry
- ic.md.um    User Management
- ic.md.rt    Runtime Mode

- ic.db       Database
- ic.db.sq    Database SQL Server
- ic.db.sq.sp Database SQL Server Setup
- ic.db.or    Database Oracle
- ic.db.qy    Database Query

- ic.dm
- ic.dm.um    Domain User Management
- ic.dm.at    Audit Trail
- ic.dm.lc    Domain Lifecycle
- ic.dm.dv    Domain Development
- ic.dm.dv.dc Domain Development Documentation
- ic.dm.ft    Fulltext
- ic.dm.un    Unit of Measurement
- ic.dm.vs    Vault Server

- ic.xm       XML Interface

- ic.sk       SDK
- ic.sk.ut    SDK Utils

- ic.cf       Configuration

- ic.wb       Web Service

- ic.sc       Security
- ic.sc.ad    Security Audit