public void Init(elogprofile logprofile) { if (m_Logs == null) { m_Logs = new ListDictionary(); } if (m_Logs.Contains(Convert.ToString(logprofile))) { return; } m_LogMethods = new LogMethods(); m_Logs.Add(Convert.ToString(logprofile), m_LogMethods); Profile = logprofile; if (m_Logs.Count > 1 | logprofile != elogprofile.primary) { //Once there are more than just the primary log profile then the properties //can no longer default to just the primary profile. m_DefaultToPrimaryProfile = false; } }
public static void LogHeader(elogprofile logprofile, string sText, elogheaderlevel logheaderlevel) { string sHeader = ""; DateTime dt = DateTime.Now; switch (logheaderlevel) { case elogheaderlevel.Level_1: sHeader = "======(" + System.AppDomain.CurrentDomain.FriendlyName + ") ==== " + sText + "============ Date:" + dt.ToString("yyyyMMdd") + " Time:" + dt.ToString("hh:mm:ss"); break; case elogheaderlevel.Level_2: sHeader = "------" + sText + " ============ Time:" + dt.ToString("hh:mm:ss"); break; case elogheaderlevel.Level_3: sHeader = "---" + sText + " --- Time:" + dt.ToString("hh:mm:ss"); break; } LogThis(sHeader, eloglevel.info, elogprefix.none); }
public static LogMethods GetProfile(elogprofile logprofile) { return((LogMethods)m_Logs[Convert.ToString(logprofile)]); }
public static void LogReset(elogprofile logprofile) { ((LogMethods)m_Logs[Convert.ToString(logprofile)]).LogReset(); }
public static void LogThis(elogprofile logprofile, string logtext, eloglevel loglevel, elogprefix logprefix) { ((LogMethods)m_Logs[Convert.ToString(logprofile)]).LogThis(logtext, loglevel, logprefix); }
public static void SetLogPath(elogprofile logprofile) { ((LogMethods)m_Logs[Convert.ToString(logprofile)]).SetLogPath(); }
public static void UseSensibleDefaults(string logFileName, string logLocation, eloglevel logLevel) { //create an instance of Log() Log Mylog = new Log(); //init the profiles you intend to use. /* The profile concept is the only complicated thing about LogThis and unless you have some need to log in multiple different ways *in the same project* then just default to the primary profile. All the settings you see below are configuring the primary profile. To have multiple profiles you would call Mylog.Init(elogprofile.your_made_up_profile) and then set these same settings for that profile also. One possible scenerio for using multiple profiles might be having different parts of the code log to different files with different quota settings or one part to a file and the other part to the event log. It's a lame example but you get the gist hopefully. */ Mylog.Init(); //This is the same as Mylog.Init(elogprofile.primary) . /* You only need the Mylog instance just long enough to run Init. Now you can just use the static methods to perform all logging actions, which is the most of the reason I wrote LogThis. */ Mylog = null; /* Set the properties for the primary log profile. Log.Profile sets the *active* profile, and it remains the active profile unless you set it explicitly. Any calls to Log.LogThis or any other Log methods will use the active profile. */ Log.Profile = elogprofile.primary; //I prefer a simple text file log but you can change this //to use the event log also. Log.LogWhere = elogwhere.file; if (Convert.ToInt32(Log.LogLevel) < 1) { Log.LogLevel = eloglevel.error; //errors show at the minimum. } else { Log.LogLevel = logLevel; } string[] fileDefaults = DefaultLogFileAndLocation(); if (logFileName == string.Empty) Log.LogName = fileDefaults[1]; else Log.LogName = logFileName; if (logLocation == string.Empty) Log.LogBasePath = fileDefaults[0]; else Log.LogBasePath = logLocation; //evaluate the quota size as meaning kbytes. Log.LogQuotaFormat = elogquotaformat.kbytes; //So, max logfile size = (Log.LogQuotaFormat * Log.LogSizeMax) Log.LogSizeMax = 100; //Every Log.LogPeriod the log file will roll over to a new file. Log.LogPeriod = elogperiod.month; //The log filename will be formatted this way. Log.LogNameFormat = elognameformat.date_name; Log.SetLogPath(); /* ok, all things required as init configuration have now been set. Simply call Log.LogThis or Log.LogHeader anywhere in your code. Example: Log.LogHeader(Log.LogName + ": Starting up",elogheaderlevel.Level_1); ... Log.LogThis("Main: " + e.Message,eloglevel.error); ... Log.LogHeader(Log.LogName + ": Exiting",elogheaderlevel.Level_1); */ }
public void Init(elogprofile logprofile) { if (m_Logs == null) { m_Logs = new ListDictionary(); } if (m_Logs.Contains(Convert.ToString(logprofile))) { return; } m_LogMethods = new LogMethods(); m_Logs.Add(Convert.ToString(logprofile),m_LogMethods); Profile = logprofile; if (m_Logs.Count > 1 | logprofile != elogprofile.primary) { //Once there are more than just the primary log profile then the properties //can no longer default to just the primary profile. m_DefaultToPrimaryProfile = false; } }
public static void LogThis(elogprofile logprofile, string logtext,eloglevel loglevel, elogprefix logprefix) { ((LogMethods)m_Logs[Convert.ToString(logprofile)]).LogThis(logtext,loglevel,logprefix); }
public static void LogHeader(elogprofile logprofile, string sText,elogheaderlevel logheaderlevel) { string sHeader = ""; DateTime dt = DateTime.Now; switch(logheaderlevel) { case elogheaderlevel.Level_1: sHeader = "======(" + System.AppDomain.CurrentDomain.FriendlyName + ") ==== " + sText + "============ Date:" + dt.ToString("yyyyMMdd") + " Time:" + dt.ToString("hh:mm:ss") ; break; case elogheaderlevel.Level_2: sHeader = "------" + sText + " ============ Time:" + dt.ToString("hh:mm:ss") ; break; case elogheaderlevel.Level_3: sHeader = "---" + sText + " --- Time:" + dt.ToString("hh:mm:ss") ; break; } LogThis(sHeader, eloglevel.info, elogprefix.none); }
public static LogMethods GetProfile(elogprofile logprofile) { return (LogMethods) m_Logs[Convert.ToString(logprofile)]; }