LogFileEventConsumer

Log File Event Consumer

The LogFileEventConsumer class writes customized strings to a text log file when events are delivered to it.

On this page

Main example

List instances

# All instances of LogFileEventConsumer, with the main properties
Get-CimInstance -ClassName LogFileEventConsumer -Namespace 'root/subscription' |
    Select-Object -Property Name, Filename, IsUnicode, MachineName

Examples

Filter with WQL

# WQL filter evaluated by the provider: only the instances where IsUnicode is TRUE
$cimParameters = @{
    ClassName = 'LogFileEventConsumer'
    Namespace = 'root/subscription'
    Filter    = 'IsUnicode = TRUE'
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, Filename, IsUnicode, MachineName

The filter is evaluated by the WMI provider: less data is transferred than with Where-Object.

Query a remote computer (CIM session)

review before running
# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
    $cimParameters = @{
        CimSession = $cimSession
        ClassName  = 'LogFileEventConsumer'
        Namespace  = 'root/subscription'
    }
    Get-CimInstance @cimParameters |
        Select-Object -Property Name, Filename, IsUnicode, MachineName
} finally {
    Remove-CimSession -CimSession $cimSession
}

WSMan (WinRM) is used by default. For a host without WinRM, create the session with -SessionOption (New-CimSessionOption -Protocol Dcom). Add -Credential to use another account.

Show the class structure

# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName LogFileEventConsumer -Namespace 'root/subscription'
$cimClass.CimClassProperties |
    Select-Object -Property Name, CimType, Flags

Properties

8 of 8 properties
NameTypeAccessDescription
CreatorSIDuint8[]read

Security identifier (SID) that uniquely identifies the user who creates a filter. WMI stores the SID of the user who creates an instance of __EventConsumer or the Administrator SID, depending on the operating system. For more information, see Binding an Event Filter with a Logical Consumer and Monitoring and Responding to Events with Standard Consumers.

Code
# Value of CreatorSID for each instance
# CreatorSID is an array: -ExpandProperty returns its items one by one
$cimParameters = @{
    ClassName = 'LogFileEventConsumer'
    Namespace = 'root/subscription'
    Property  = 'CreatorSID'
}
Get-CimInstance @cimParameters |
    Select-Object -ExpandProperty CreatorSID
Filenamestringread

Name of a file that includes the path to which the log entries are appended. If the file does not exist, LogFileEventConsumer attempts to create it. The consumer fails when the path does not exist, or when the user who creates the consumer does not have write permissions for the file or path.

Code
# Value of Filename for each instance
$cimParameters = @{
    ClassName = 'LogFileEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'Filename')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, Filename
IsUnicodebooleanread

If TRUE, the log file is a Unicode text file. If FALSE, the log file is a multibyte code text file. If the file exists, this property is ignored and the current file setting is used. For example, if IsUnicode is FALSE, but the existing file is a Unicode file, then Unicode is used. If IsUnicode is TRUE, but the file is multibyte code, then multibyte code is used.

Code
# Value of IsUnicode for each instance
$cimParameters = @{
    ClassName = 'LogFileEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'IsUnicode')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, IsUnicode
MachineNamestringread

Name of the computer to which Windows Management Instrumentation (WMI) sends events.

Code
# Value of MachineName for each instance
$cimParameters = @{
    ClassName = 'LogFileEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'MachineName')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, MachineName
MaximumFileSizeuint64read

Maximum size of a log file in bytes. If the primary file exceeds its maximum size, the contents are moved to a different file and the primary file is emptied. A value of 0 (zero) means there is no size limit. The default value is 65,535 bytes. The size of the file is checked before a write operation. Therefore, you can have a file that is slightly larger than the specified size limit. The next write operation catches it and starts a new file.

The following list identifies the naming structure for the backup file:

  • If the original filename is 8.3, the extension is replaced by a string in the format of "001", "002", and so on with the smallest number larger than all the previously used and chosen numbers. If "999" is used, then the number chosen is the smallest unused number.
  • If the original filename is not 8.3, a string in the format of "001", "002", and so on is appended to the file name.

For more information about using uint64 values in scripts, see Scripting in WMI.

Code
# Value of MaximumFileSize for each instance
# MaximumFileSize is expressed in bytes: converted to GB
$cimParameters = @{
    ClassName = 'LogFileEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'MaximumFileSize')
}
Get-CimInstance @cimParameters |
    Select-Object -Property @(
        'Name'
        @{ Name = 'MaximumFileSizeGB'; Expression = { [math]::Round($_.MaximumFileSize / 1GB, 2) } }
    )
MaximumQueueSizeuint32read

Maximum queue for a specific consumer, in bytes.

Code
# Value of MaximumQueueSize for each instance
$cimParameters = @{
    ClassName = 'LogFileEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'MaximumQueueSize')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, MaximumQueueSize
Name keystringread

Unique name for this consumer.

Code
# Value of Name for each instance
$cimParameters = @{
    ClassName = 'LogFileEventConsumer'
    Namespace = 'root/subscription'
    Property  = 'Name'
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name
Textstringread

Standard string template for the text of a log entry.

Code
# Value of Text for each instance
$cimParameters = @{
    ClassName = 'LogFileEventConsumer'
    Namespace = 'root/subscription'
    Property  = @('Name', 'Text')
}
Get-CimInstance @cimParameters |
    Select-Object -Property Name, Text

Remarks

Note: The LogFileEventConsumer does not secure the log file. Therefore, when you configure the LogFileEventConsumer, it is important to specify a directory that is secured to the level that you require.

The LogFileEventConsumer class is derived from the __EventConsumer abstract class.

Inheritance

Superclass chain

  1. __SystemClass
  2. __IndicationRelated
  3. __EventConsumer
  4. LogFileEventConsumer

Known subclasses

No known subclass.

Requirements

Namespace
root/subscription
Minimum client
Windows Vista
Minimum server
Windows Server 2008
MOF file
Wbemcons.mof
DLL
Wbemcons.dll
Class qualifiers

AMENDMENT

Microsoft source

Source: Microsoft Learn

Descriptions, properties and methods come from the Microsoft documentation (MicrosoftDocs/win32 repository), published under the CC BY 4.0 licence. Formatting and translations are specific to this site; the PowerShell examples are written for it.