Click here to Skip to main content
15,880,608 members
Articles / Desktop Programming / WPF

Easy Log Viewer. Yet another log viewer tool, but Easier.

Rate me:
Please Sign up or sign in to vote.
2.67/5 (9 votes)
3 Jun 2015Ms-RL2 min read 50.4K   1.9K   21   18
Easy Log Viewer is a tool which helps developers to easier view logs,

Introduction

Easy Log Viewer is a tool which helps developers to easier view logs, it contains these features:

1: Support all kinds of logs, ( Windows Event Log, CSV Logs, XML logs, text logs, database logs ...).

  • Open Window Event Log (Application).

    Image 1

  • Open CSV file:

    Image 2

  • Open XML file

    Image 3

  • Open Text file:

    Image 4

2: Easy to filter and search , I guess nobody want the viewer doesn't support this feature.

Image 5

Click Find Previous or Find Next to navigate between Find what:

Image 6

3: The feature should powerful, should support Contains, NotContains, StartsWith, Equal, Regex... , So I can easier to filter logs.

Image 7

4: highligh based on filters, Sometimes I want to highlight the interest items.

Image 8

5: hide or show some log records, This will allow me to focus on the log which I interested in.

Image 9

6: Bookmark support. Like Visual Studio , navigation in bookmark is easier.

Image 10

7: Annotation support, Sometimes I want to add some comments to log, so when I send them to others, other can see my comments.

Image 11

8: Save the log, It should save the log and the settings of the Log.

9: The UI should be stupid and simple, and powerful, It should be easy to use, and easy to rearrange, and support full screen mode.

Free Style

Image 12

Full Screen Mode

Image 13

Image 14

Background

There're lots of logging framework, like log4j, log4net, NLog, Microsoft Enterprise Logging Framework...

These logging frameworks help developer to Log messages in application, with these frameworks, You can log your messages to DB, to Console, to File, to other computers, to what ever you want.

However I found there is NO Log Viewer Tool which support all kinds of logging targets.

Some tool only support one kinds of Logging format, and some doesn't have the feature I want, That's why I created this tool!.

Using the code

EasyLogViewer support plugin,

For example, if you want to read your log entries from other places,

  1. Create a project , and add reference to EasyLogViewer.IHandler.dll
  2. Implement the IReadLogFileHandler interface,
  3. Put the build bin folder to Plugins folder, like other plugin does.
C#
namespace EasyLogViewer.IHandler
{
    public interface IReadLogFileHandler : IBaseHandler
    {
        object Execute(string fileName, Action<IEnumerable<ExpandoObject>> newLogEntriesCallback, HandledEventArgs args);
    }
}

Below is an example of how to write a text file reader:

C#
public class LineFileHandler : IReadLogFileHandler
{
	public int Priority
	{
		get { return Int32.MinValue; }
	}

	public object Execute(string fileName, Action> newLogEntriesCallback,HandledEventArgs args)
	{
		var result = new List<ExpandoObject>();
		using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
		{
			using (var sr = new StreamReader(fs))
			{
				while (sr.Peek() >= 0)
				{
					dynamic obj = new ExpandoObject();
					obj.Message = sr.ReadLine();

					result.Add(obj);
				}
			}
		}

		args.Handled = true;

		return result;
	}
}

Your plugin will be executed by PluginManager class.

C#
public static class PluginManager
	{
		private static readonly Dictionary<object, object=""> pluginCache = new Dictionary<object, object="">();
		private static readonly List<type> pluginTypes = new List<type>();

		public static void LoadPlugins()
		{
			foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
			{
				LoadPlugins(assembly);
			}

			// load 3rd last.
			string[] pluginFolders = Directory.GetDirectories("Plugins");
			foreach (string pluginFolder in pluginFolders)
			{
				string[] files = Directory.GetFiles(pluginFolder, "*.dll");

				foreach (string file in files)
				{
					Assembly assembly = Assembly.LoadFrom(Environment.CurrentDirectory + "\\" + file);

					//Assembly assembly = AppDomain.CurrentDomain.Load(Environment.CurrentDirectory + "\\" + file);

					LoadPlugins(assembly);
				}
			}
		}

		public static object RunPlugins<t>(this object owner, params object[] handleArgs) where T : IBaseHandler
		{
			object result = null;

			var eventArgs = new HandledEventArgs(false);

			List<object>newArgs = handleArgs.ToList();
			newArgs.Add(eventArgs);
			object[] combineArgs = newArgs.ToArray();

			List<t> handlers = GetPlugins<t>(owner);
			MethodInfo methodInfo = null;
			foreach (T handler in handlers)
			{
				try
				{
					if (methodInfo == null)
					{
						methodInfo = typeof(T).GetMethod("Execute");
					}

					if (eventArgs.Handled == false)
					{
						result = methodInfo.Invoke(handler, combineArgs);

						if (eventArgs.Handled)
						{
							EventLogHelper.LogInformation(string.Format("Parse Log Success {0}", handler));
						}
					}
					else
					{
						break;
					}
				}
				catch (Exception ex)
				{
					//swallow this exception, do the next parser.
					EventLogHelper.LogError("This plugin has error,...", ex);
				}
			}

			return result;
		}

		private static List<t> GetPlugins<t>(object owner) where T : IBaseHandler
		{
			if (!pluginCache.ContainsKey(owner) ||
				!pluginCache[owner].OfType<t>().Any())
			{
				List<type> matchPluginTypes = pluginTypes.Where(t => t.Implements<t>()).ToList();

				List<object> plugins =
					(from matchPluginType in matchPluginTypes
					 where matchPluginType.IsClass
					 select Activator.CreateInstance(matchPluginType)).ToList();

				pluginCache[owner] = plugins;
			}

			return pluginCache[owner]
				.OfType<t>()
				.OrderByDescending(t => t.Priority)
				.ToList();
		}

		private static void LoadPlugins(Assembly assembly)
		{
			IList<type> types = assembly.TypesImplementing<ibasehandler>();
			foreach (Type type in types)
			{
				pluginTypes.Add(type);
			}
		}
	}

Please notice the RunPlugins<T> method, this method will pass the parameters to plugin, and run the Execute method by reflection.

So what's next?

Features still outstanding for EasyLogViewer:

  • Export logs in several formats (CSV, XML,...).
  • Highlight the method Enter and Exit,
  • Group methods.
  • Group filters, so filters can And/Or.
  • Column Display Plugin.
  • Quick navigate between find logs.
  • Got any ideas you'd like to share? Ping me.

Points of Interest

http://logging.apache.org/log4net/

http://nlog-project.org/

History

30 May 2015: Version 1.0

  • Initial release.

License

This article, along with any associated source code and files, is licensed under Microsoft Reciprocal License


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionWhere find EasyLogViewer ? Pin
pleveill29-Dec-15 12:01
pleveill29-Dec-15 12:01 
AnswerRe: Where find EasyLogViewer ? Pin
LoveJenny29-Dec-15 21:47
LoveJenny29-Dec-15 21:47 
GeneralRe: Where find EasyLogViewer ? Pin
pleveill30-Dec-15 1:48
pleveill30-Dec-15 1:48 
GeneralRe: Where find EasyLogViewer ? Pin
Member 244330626-Oct-17 1:41
Member 244330626-Oct-17 1:41 
QuestionHow can I view Windows Events Security log ? Pin
Kiliuszkin115-Aug-15 0:15
Kiliuszkin115-Aug-15 0:15 
AnswerRe: How can I view Windows Events Security log ? Pin
LoveJenny6-Aug-15 16:00
LoveJenny6-Aug-15 16:00 
GeneralRe: How can I view Windows Events Security log ? Pin
Kiliuszkin116-Aug-15 22:03
Kiliuszkin116-Aug-15 22:03 
GeneralRe: How can I view Windows Events Security log ? Pin
LoveJenny6-Aug-15 23:01
LoveJenny6-Aug-15 23:01 
GeneralRe: How can I view Windows Events Security log ? Pin
Kiliuszkin117-Aug-15 5:30
Kiliuszkin117-Aug-15 5:30 
SuggestionPlugins and MEF Pin
kiquenet.com12-Jun-15 4:12
professionalkiquenet.com12-Jun-15 4:12 
GeneralRe: Plugins and MEF Pin
LoveJenny14-Jun-15 15:48
LoveJenny14-Jun-15 15:48 
QuestionOther viewer Pin
kiquenet.com12-Jun-15 1:15
professionalkiquenet.com12-Jun-15 1:15 
AnswerRe: Other viewer Pin
LoveJenny14-Jun-15 15:49
LoveJenny14-Jun-15 15:49 
GeneralMy vote of 5 Pin
Prafulla Hunde3-Jun-15 8:26
Prafulla Hunde3-Jun-15 8:26 
GeneralRe: My vote of 5 Pin
LoveJenny3-Jun-15 12:54
LoveJenny3-Jun-15 12:54 
QuestionWhere is the source? Pin
James Huebsch3-Jun-15 7:28
James Huebsch3-Jun-15 7:28 
AnswerRe: Where is the source? Pin
LoveJenny3-Jun-15 12:56
LoveJenny3-Jun-15 12:56 
Sorry, James, this tool doesn't open source,

However, It's free to use , if you want the source, please send me a mail (343875957@qq.com). thanks.
QuestionFailed to load resource: the server responded with a status of 404 (File Not Found) Pin
Anders Eriksson3-Jun-15 6:14
Anders Eriksson3-Jun-15 6:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.