0

I have an issue with writing event log to Windows Event Viewer. I want to register a custom Event Log under Applications and Services Logs menu but I have no idea to do it in Python (I am using PyWin32 in this case). Basically we can register a custom log with Powershell's New-EventLog but I want to do it in Python.

These are some attemps I have done:

  • Create an event log with Powershell's New-EventLog:

New-EventLog -LogName <Log Name> -Source <Source>

  • In Python, open a handler with registered Log Name:
import win32evtlog

hand = win32evtlog.OpenEventLog(None, 'CustomRegisteredEventLog')
# then write to Event Log
win32evtlog.ReportEvent(hand, win32evtlog.EVENTLOG_INFORMATION_TYPE, 0, 0, None, ['some message'], None)

Those steps above actually works, the log is successfully submitted to event log, but I still need to register the Event Log with Python. Could anyone guide me on how to do this on Python?

1 Answer 1

1

I post the full code of my current understanding of this for you below.

import win32evtlogutil
import win32evtlog
import sys

print("Python {0} on {1}".format(sys.version,sys.platform))

variable = ["x,","y","z"]


App_Name = "Python test"
App_Event_ID = 10001
App_Event_Category = 90
#App_Event_Type = win32evtlog.EVENTLOG_WARNING_TYPE
App_Event_Str = ["scanned: {}".format(var) for var in variable]
App_Event_Data= b"xyz"

'''

win32evtlogutil.ReportEvent(ApplicationName, EventID, EventCategory,EventType,Inserts, Data, SID)

'''


win32evtlogutil.ReportEvent(App_Name,App_Event_ID, eventCategory= App_Event_Category,
                                eventType=win32evtlog.EVENTLOG_INFORMATION_TYPE,
                                strings=App_Event_Str,data=App_Event_Data)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.