1 /*---------------------------------------------------------------------------* 2 3 Copyright (C) Nintendo. All rights reserved. 4 5 These coded instructions, statements, and computer programs contain 6 proprietary information of Nintendo of America Inc. and/or Nintendo 7 Company Ltd., and are protected by Federal copyright law. They may 8 not be disclosed to third parties or copied or duplicated in any form, 9 in whole or in part, without the prior written consent of Nintendo. 10 11 *---------------------------------------------------------------------------*/ 12 using System; 13 using System.Collections.Generic; 14 using System.Text; 15 using System.Diagnostics; 16 17 namespace CafeX 18 { 19 public static class EventStatus 20 { 21 public const string BEGIN = "BEGIN"; 22 public const string END = "END"; 23 public const string DISCRETE = "DISCRETE"; 24 } 25 26 public static class EventProcess 27 { 28 public const string IOP = "IOP"; 29 public const string PPC = "PPC"; 30 public const string TITLE = "TITLE"; 31 public const string CAFEX = "CafeX"; 32 } 33 //This is a singleton class (Not Multithread safe) 34 public sealed class CafeXEventtLog 35 { 36 private static readonly CafeXEventtLog instance = new CafeXEventtLog(); 37 private const string logName = "Application"; 38 39 private string logSource = "CafeProf"; 40 41 public string LogSource 42 { 43 get { return logSource; } 44 set { logSource = value; } 45 } 46 47 public static CafeXEventtLog Instance 48 { 49 get 50 { 51 return instance; 52 } 53 } 54 CafeXEventtLog()55 private CafeXEventtLog() { } 56 CreateLog()57 public bool CreateLog() 58 { 59 bool Result = false; 60 61 try 62 { 63 System.Diagnostics.EventLog.CreateEventSource(logSource, logName); 64 System.Diagnostics.EventLog EventLog = new System.Diagnostics.EventLog(); 65 66 EventLog.Source = logSource; 67 EventLog.Log = logName; 68 69 EventLog.WriteEntry(logSource + " successfully initialized.", System.Diagnostics.EventLogEntryType.Information); 70 71 Result = true; 72 } 73 catch 74 { 75 Result = false; 76 } 77 78 return Result; 79 } 80 WriteToEventLog(Int32 id, string strErrDetail)81 public void WriteToEventLog(Int32 id, string strErrDetail) 82 { 83 System.Diagnostics.EventLog xEventLog = new System.Diagnostics.EventLog(); 84 85 try 86 { 87 if (!System.Diagnostics.EventLog.SourceExists(this.logSource)) 88 { 89 this.CreateLog(); 90 } 91 xEventLog.Source = this.logSource; 92 xEventLog.WriteEntry(strErrDetail, 93 System.Diagnostics.EventLogEntryType.Information, 94 id); 95 } 96 catch (Exception ex) 97 { 98 xEventLog.Source = this.logSource; 99 xEventLog.WriteEntry("INFORMATION: " + ex.Message, 100 System.Diagnostics.EventLogEntryType.Information); 101 } 102 finally 103 { 104 xEventLog.Dispose(); 105 xEventLog = null; 106 } 107 } 108 WriteToEventLog(Int32 id, DateTime time, string strErrDetail)109 public void WriteToEventLog(Int32 id, DateTime time, string strErrDetail) 110 { 111 WriteToEventLog(id, string.Format("[{0}] {1}", time.ToString("HH:mm:ss:fff"), strErrDetail)); 112 } 113 WriteToEventLog(Int32 id, DateTime time, string status, string process, string strErrDetail)114 public void WriteToEventLog(Int32 id, DateTime time, string status, string process, string strErrDetail) 115 { 116 WriteToEventLog(id, string.Format("[{0}][{1}][{2}] {3}", time.ToString("HH:mm:ss:fff"), status, process, strErrDetail)); 117 } 118 } 119 } 120