Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet236/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   232   233   234   235   236   237   238   239   ...   453
Creating Log Files
At one time, administrators relied on text log files to store information from applications. However, 
most applications today output complex information that’s hard to read within a text file. If you plan 
to create log files for your application, you probably want to store them in XML format to make them 
easy to ready and easy to import into a database. Chapter 13 describes how to work with XML files.
548592c10.indd 220
2/24/10 12:48:34 PM
www.finebook.ir


Providing Status Information
 

 
221
Using the Event Log
Many applications rely on the event log as a means to output data to the administrator. Of all of the 
methods that Microsoft has created for outputting error and status information, the event log has 
been around the longest and is the most successful. Fortunately, for the IronPython developer, using 
the event log is extremely easy and it’s the method that you should use most often. Listing 10-11 
shows just how easy it is to write an event log entry.
LISTINg 10-11: 
 Writing an event log entry
# Import the required assemblies.
from System.Diagnostics import EventLog, EventLogEntryType
# Create the event log entry.
ThisEntry = EventLog(‘Application’, ‘Main’, ‘SampleApp’)
# Write data to the entry.
ThisEntry.WriteEntry(‘This is a test!’, EventLogEntryType.Information)
# Pause after the debug session.
raw_input(‘Event log entry written...’)
The 
EventLog()
constructor accepts a number of different inputs. The form shown in the example 
defines the log name, machine name, and the application name. In most cases, this is all the infor-
mation you need to start writing event log entries.
After you create 
ThisEntry
, you can use it to begin writing event log entries as needed using the 
WriteEntry()
method. The 
WriteEntry()
is overloaded to accept a number of information for-
mats — the example shows what you’ll commonly use for simple entries. You can see other forms
of the 
WriteEntry()
method at 
http://msdn.microsoft.com/library/system.diagnostics 
.eventlog.writeentry.aspx
.
In this case, the 
WriteEntry()
provides a message and defines the kind of event log entry to create. 
You can also create warning, error, success audit, and failure audit messages. Figure 10-16 shows 
the results of running this example.
FIgURE 10-16: 
The example outputs data to the event log.
548592c10.indd 221
2/24/10 12:48:34 PM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   232   233   234   235   236   237   238   239   ...   453




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish