Exemple #1
0
        private void MakeEntry(NetLogEntryTypes type, string str)
        {
            if ((type & IgnoreTypes) == type)
            {
                return;
            }

            if (type != NetLogEntryTypes.Break)
            {
                ConsoleColor wasColor = Console.ForegroundColor;
                // TODO:
                //Console.ForegroundColor = LogEntryTypeColors[(int)type];
                Console.WriteLine(str);
                Console.ForegroundColor = wasColor;
            }

            NetLogEntry entry = new NetLogEntry();

            entry.TimeMillis = (long)(NetTime.Now * 1000.0);
            entry.Type       = type;
#if DEBUG
            // get call stack
            StackTrace trace  = new StackTrace(2, true);
            StackFrame frame  = trace.GetFrame(0);
            MethodBase method = frame.GetMethod();
            entry.Where = method.Name + "() in " + method.DeclaringType.Name;
#else
            entry.Where = "";
#endif
            entry.What = str;

            if (m_outputToFile)
            {
                m_entries.Enqueue(entry);
            }

            if (LogEvent != null)
            {
                NetLogEventArgs args = new NetLogEventArgs();
                args.Entry = entry;
                LogEvent(this, args);
            }

            if (Thread.CurrentThread == m_mainThread && m_entries.Count > 0)
            {
                Flush();
            }
        }
Exemple #2
0
        public void Flush()
        {
            if (m_fileToUse != m_file)
            {
                m_fileToUse = Path.GetFullPath(m_fileToUse);
                m_file      = m_fileToUse;
                StreamWriter writer = new StreamWriter(m_file);
                writer.Write(@"
<!DOCTYPE HTML PUBLIC \'-//W3C//DTD HTML 4.01 Transitional//EN\'>
<HTML>
	<HEAD>
		<TITLE>Log</TITLE>
		<STYLE>
TD {
	font-family: verdana;
	font-size: 10px;
}
BODY {
	font-family: verdana;
	font-size: 10px;
	line-height: 16px;
	vertical-align: top;
}
H1 {
	font-family: verdana;
	font-size: 22px;
	margin-left: 20px;
	font-weight: bold;
}
.inf { color: #000000; border-bottom: 1px solid #CCCCCC; vertical-align: top; }
.suc { color: #008800; border-bottom: 1px solid #CCCCCC; vertical-align: top; }
.fai { color: #AA2200; border-bottom: 1px solid #CCCCCC; vertical-align: top; }
.dbg { color: #008800; border-bottom: 1px solid #CCCCCC; vertical-align: top; }
.vrb { color: #999999; border-bottom: 1px solid #CCCCCC; vertical-align: top; }
.wrn { font-weight: bold; color: #DD8800; border-bottom: 1px solid #CCCCCC; vertical-align: top; }
.err { font-weight: bold; color: #FF0000; border-bottom: 1px solid #CCCCCC; vertical-align: top; }
.brk { color: #FF0000; border-bottom: 1px solid #000000; vertical-align: top; }
.lbl { padding: 14px 4px 2px 22px; font-family: arial; font-size: 14px; font-weight: bold; color: #000000; background-color: #EEEEEE; border-top: 1px solid #000000; border-bottom: 1px solid #000000; }

U { text-align: right; text-decoration: none; width: 75px; margin-right: 6px; vertical-align: top; padding-right: 2px; }
Q { text-decoration: none; width: 275px; margin-left: 8px; margin-right: 6px; vertical-align: top; }
		</STYLE>
	</HEAD>
	<BODY>
");
                try
                {
                    writer.WriteLine("\t\t<DIV CLASS=\"inf\">{0}</DIV>", System.Environment.CommandLine);
                    writer.WriteLine("\t\t<DIV CLASS=\"inf\">{0}\\{1} @ {2} ({3})</DIV>", System.Environment.UserDomainName, System.Environment.UserName, System.Environment.MachineName, System.Environment.OSVersion);
                    writer.WriteLine("\t\t<DIV CLASS=\"inf\">.NET Framework version: {0}</DIV>", System.Environment.Version);
                    writer.WriteLine("\t\t<DIV CLASS=\"inf\">Log started {0}</DIV>", DateTime.Now);
                    writer.WriteLine("\t\t<DIV CLASS=\"brk\"></DIV>");
                }
                finally { }

                writer.Close();
            }

            while (m_entries.Count > 0)
            {
                NetLogEntry entry = m_entries.Dequeue();
                if (m_file != null)
                {
                    StringBuilder htmlBuilder = new StringBuilder(63);

                    htmlBuilder.AppendFormat("<DIV CLASS=\"{0}\">{1}", LogEntryTypeName[entry.Type], System.Environment.NewLine);
                    htmlBuilder.AppendFormat("<U>{0}</U>", entry.TimeMillis);

                    if (entry.Where == null)
                    {
                        htmlBuilder.AppendLine("<Q>-</Q>");
                    }
                    else
                    {
                        try
                        {
                            htmlBuilder.AppendFormat("<Q>{0}</Q>", entry.Where);
                        }
                        catch (Exception ex)
                        {
                            htmlBuilder.AppendFormat("<Q>{0}</Q>", ex.ToString());
                        }
                    }

                    htmlBuilder.Append(entry.What);

                    htmlBuilder.AppendLine("</DIV>");

                    File.AppendAllText(m_file, htmlBuilder.ToString(), Encoding.ASCII);
                }
            }
        }
Exemple #3
0
		private void MakeEntry(NetLogEntryTypes type, string str)
		{
			if ((type & IgnoreTypes) == type)
				return;

			if (type != NetLogEntryTypes.Break)
			{
				ConsoleColor wasColor = Console.ForegroundColor;
				// TODO:
				//Console.ForegroundColor = LogEntryTypeColors[(int)type];
				Console.WriteLine(str);
				Console.ForegroundColor = wasColor;
			}

			NetLogEntry entry = new NetLogEntry();
			entry.TimeMillis = (long)(NetTime.Now * 1000.0);
			entry.Type = type;
#if DEBUG
			// get call stack
			StackTrace trace = new StackTrace(2, true);
			StackFrame frame = trace.GetFrame(0);
			MethodBase method = frame.GetMethod();
			entry.Where = method.Name + "() in " + method.DeclaringType.Name;
#else
			entry.Where = "";
#endif
			entry.What = str;

			if (m_outputToFile)
				m_entries.Enqueue(entry);

			if (LogEvent != null)
			{
				NetLogEventArgs args = new NetLogEventArgs();
				args.Entry = entry;
				LogEvent(this, args);
			}

			if (Thread.CurrentThread == m_mainThread && m_entries.Count > 0)
				Flush();
		}