2

I have a log file "logs.log" that include the status of one of the applications, and I want to write these logs in Windows Events Viewer.

the output in that file as below:

24/01/2019 16:33:26   app(12744.13964) <SYSTEM> SERVICE.app.Activity: Stopping service...

Is there any way to write them in Windows Events Viewer?

BR

1

Is there any way to write them in Windows Events Viewer?

You can write custom events to event logs using EventCreate.

For a working example see my answer Windows event id for battery level change.


EVENTCREATE

Add a message to the Windows event log, requires administrator rights.

Syntax
      EVENTCREATE [/S system [/U username [/P [password]]]] /ID eventid
            [/L logname] [/SO srcname] /T type /D description

Key:
    /S system         The remote system to connect to.

    /U [domain\]user  User credentials under which to execute.

    /P [password]     Password for user, will prompt if omitted.

    /L logname        The event log to create an event in.

    /T type           The type of event to create: SUCCESS, ERROR, WARNING, INFORMATION.

    /SO source        The source to use for the event  A text string that represents the 
                      application or component that is generating the event. 
                      Default='eventcreate'

    /ID id            Event ID, a number between 1 - 1000.

    /D description    Description text for the new event.

    /?                Help

Source EventCreate - Windows CMD - SS64.com


Further Reading

1

You may use PowerShell to write to the Even Viewer.

The command to use is Write-EventLog, requiring administrator privileges.

Example: Write an event to the Application event log, using an elevated PowerShell script:

PS C:\> Write-EventLog -LogName "Application" -Source "MyApp" -EventID 3001 -EntryType Information -Message "MyApp added a user-requested feature to the display." -Category 1 -RawData 10,20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.