question

ShubhamSharma-0128 avatar image
0 Votes"
ShubhamSharma-0128 asked ·

I want to create a custom folder in the Application and services log area in windows event logs.

I am trying to create a custom folder in the Application and services log area in windows event logs.
Inside the folder I want to create two custom area’s ex: Area1, Area2. In Area1, I want to write the logs from one source and In Area2, I want to write logs from another source.

Original i want to do it using .net c# but as couldn't do it using c# so
I used powershell script to achieve this.

the code is below:


$PrimaryEventKey = 'Comp1'
$ApplicationName = 'App1'
$LogName = 'TSP'

$primarylocation = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\WINEVT\Channels'
$LogName = $PrimaryEventKey + '-' + $ApplicationName + '-' + $LogName
$EventRoot = (Join-Path $primarylocation $LogName)

if (!(Test-Path $EventRoot))
{
New-Item -Path ($secondarylocation + '/' + $Logname)
New-ItemProperty -Path ($secondarylocation + '/' + $Logname) -Name providerGuid -PropertyType String -Value "{$($GUID)}"
New-Item -Path $EventRoot
New-ItemProperty -Path $EventRoot -Name Enabled -PropertyType DWord -Value 1
New-ItemProperty -Path $EventRoot -Name Type -PropertyType DWord -Value 1
New-ItemProperty -Path $EventRoot -Name Isolation -PropertyType DWord -Value 0
New-ItemProperty -Path $EventRoot -Name RestrictGuestAccess -PropertyType String -Value 1
New-ItemProperty -Path $EventRoot -Name OwningPublisher -PropertyType String -Value "{$($GUID)}"
}
else
{
Write-Warning 'Event Log (Key) Already exists in registry'
}

Write into the event log (Example)


$eventType = ([System.Diagnostics.EventLogEntryType]::Information)
$evt = New-Object System.Diagnostics.EventLog($LogName)
$evt.Source = "SomeSource" $evt.WriteEntry("random message", $eventType, 60001)

By running this script I am able to create folder hierarchy but when I go to see the event logs It is showing error like:

How to resolve this issue or is there any alternative approach to do it ?
Or any other way to create folder structure and then write logs in .net or through script ?

![![73405-image.png][1]][1] [1]: /answers/storage/attachments/73309-image.png

windows-serverwindows-server-powershell
image.png (91.1 KiB)
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered ·

Hi,

Please check if the solution below works for you.

https://stackoverflow.com/questions/26335960/create-event-log-in-sub-directory-under-applications-and-settings-logs

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.