Click here to Skip to main content
15,884,739 members
Articles / Security

A simple plug-in engine using Reflection

Rate me:
Please Sign up or sign in to vote.
4.91/5 (22 votes)
26 Sep 2012CPOL11 min read 66.1K   1.1K   95  
This article describes how to create and use configurable plug-ins in your application.
using System;
using System.Linq;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;

namespace PluginDemo
{
    internal static class Log
    {
        /// <summary>
        /// Writes a message to the Windows Event Log
        /// </summary>
        /// <param name="message">Message to write</param>
        /// <param name="level">Message's type</param>
        public static void Write(string message, EventLogEntryType level = EventLogEntryType.Information)
        {
            using (EventLog e = new EventLog("Application", Environment.MachineName, Assembly.GetCallingAssembly().GetName().Name))
            {
                e.WriteEntry(message, level);
            }
        }

        /// <summary>
        /// Writes a message to the Windows Event Log
        /// </summary>
        /// <param name="message">Message to write</param>
        /// <param name="source">Message's source</param>
        /// <param name="level">Message's type</param>
        public static void Write(string message, string source, EventLogEntryType level = EventLogEntryType.Information)
        {
            using (EventLog e = new EventLog("Application", Environment.MachineName, source))
            {
                e.WriteEntry(message, level);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


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

Comments and Discussions