public void TestGetEntryType()
		{
			EventLogAppender eventAppender = new EventLogAppender();
			eventAppender.ActivateOptions();

			Assert.AreEqual(
				EventLogEntryType.Information,
				GetEntryType(eventAppender, Level.All));

			Assert.AreEqual(
				EventLogEntryType.Information,
				GetEntryType(eventAppender, Level.Debug));

			Assert.AreEqual(
				EventLogEntryType.Information,
				GetEntryType(eventAppender, Level.Info));

			Assert.AreEqual(
				EventLogEntryType.Warning,
				GetEntryType(eventAppender, Level.Warn));

			Assert.AreEqual(
				EventLogEntryType.Error,
				GetEntryType(eventAppender, Level.Error));

			Assert.AreEqual(
				EventLogEntryType.Error,
				GetEntryType(eventAppender, Level.Fatal));

			Assert.AreEqual(
				EventLogEntryType.Error,
				GetEntryType(eventAppender, Level.Off));
		}
示例#2
0
            /// <summary>
            /// Verifies that for each event log level, the correct system
            /// event log enumeration is returned
            /// </summary>
            [Test] public void TestGetEntryType()
            {
                EventLogAppender eventAppender = new EventLogAppender();

                Assertion.AssertEquals(
                    System.Diagnostics.EventLogEntryType.Information,
                    eventAppender.GetEntryType(Level.ALL));

                Assertion.AssertEquals(
                    System.Diagnostics.EventLogEntryType.Information,
                    eventAppender.GetEntryType(Level.DEBUG));

                Assertion.AssertEquals(
                    System.Diagnostics.EventLogEntryType.Information,
                    eventAppender.GetEntryType(Level.INFO));

                Assertion.AssertEquals(
                    System.Diagnostics.EventLogEntryType.Warning,
                    eventAppender.GetEntryType(Level.WARN));

                Assertion.AssertEquals(
                    System.Diagnostics.EventLogEntryType.Error,
                    eventAppender.GetEntryType(Level.ERROR));

                Assertion.AssertEquals(
                    System.Diagnostics.EventLogEntryType.Error,
                    eventAppender.GetEntryType(Level.FATAL));

                Assertion.AssertEquals(
                    System.Diagnostics.EventLogEntryType.Error,
                    eventAppender.GetEntryType(Level.OFF));
            }
        private static IAppender GetEventLogAppender()
        {
            var appender = new EventLogAppender
            {
                Threshold = Level.Error,
                Layout = GetPattermLayout()
            };

            var mappers = new[]
            {
                new EventLogAppender.Level2EventLogEntryType
                {
                    EventLogEntryType = EventLogEntryType.Error,
                    Level = Level.Error
                },
                new EventLogAppender.Level2EventLogEntryType
                {
                    EventLogEntryType = EventLogEntryType.Warning,
                    Level = Level.Warn
                },
                new EventLogAppender.Level2EventLogEntryType
                {
                    EventLogEntryType = EventLogEntryType.Error,
                    Level = Level.Fatal
                }
            };

            foreach (var mapper in mappers)
            {
                appender.AddMapping(mapper);
            }
            appender.ActivateOptions();
            return appender;
        }
示例#4
0
        static Log()
        {
            Config = LogConfigManager.Config;
            PatternLayout layout;
            AppenderSkeleton appender;

            switch (Config.Type)
            {
                case LogType.ConfigFromLogFile:
                    XmlConfigurator.ConfigureAndWatch(new FileInfo(Config.FileName));
                    break;
                case LogType.RollingFile:
                case LogType.RollingFileAndWinEventLog:
                    layout = new PatternLayout(Config.Pattern);
                    appender = new RollingFileAppender
                    {
                        File = Config.FileName,
                        AppendToFile = true,
                        RollingStyle = RollingFileAppender.RollingMode.Composite,
                        MaxSizeRollBackups = Config.MaxNumberOfBackupFiles,// App.Config.IsDebugConfiguration ? -1 : 100,
                        MaximumFileSize = Config.RollingFileMaximumFileSize,
                        DatePattern = Config.RollingFileDatePattern,
                        Layout = layout,
                        LockingModel = new FileAppender.MinimalLock()
                    };
                    layout.ActivateOptions();
                    appender.ActivateOptions();
                    BasicConfigurator.Configure(appender);
                    break;
                default:
                    if (Config.Type == LogType.WinEventLog ||
                        Config.Type == LogType.RollingFileAndWinEventLog)
                    {
                        layout = new PatternLayout(Config.Pattern);
                        appender = new EventLogAppender
                        {
                            LogName = App.Config.Name,
                            Layout = layout
                        };
                        layout.ActivateOptions();
                        appender.ActivateOptions();
                        BasicConfigurator.Configure(appender);
                    }
                    else if (Config.Type == LogType.VisualStudioTraceOutput)
                    {
                        layout = new PatternLayout(Config.Pattern);
                        appender = new TraceAppender
                        {
                            ImmediateFlush = true
                        };
                        layout.ActivateOptions();
                        appender.ActivateOptions();
                        appender.Layout = layout;
                        BasicConfigurator.Configure(appender);
                    }
                    break;
            }
        }
示例#5
0
 public override IAppender GetAppender()
 {
     var appender = new EventLogAppender
     {
         Threshold = Level.All,
         Layout = new PatternLayout(layoutString),
         ApplicationName = ApplicationName,
     };
     appender.ActivateOptions();
     return appender;
 }
示例#6
0
 public static ILog CreateAuditTrail(string appName, string logSection = "CustomEventLog",
     string loggerName = null, [CallerMemberName] string caller = null)
 {
     var eventLogAppender = new EventLogAppender()
     {
         ApplicationName = appName ?? "[SkyNetCloud module]",
         LogName = logSection,
     };
     var pl = new PatternLayout()
     {
         ConversionPattern = _conversionPattern,
     };
     pl.ActivateOptions();
     eventLogAppender.Layout = pl;
     eventLogAppender.ActivateOptions();
     LogManager.ResetConfiguration();
     log4net.Config.BasicConfigurator.Configure(eventLogAppender);
     return LogManager.GetLogger(loggerName ?? caller);
 }
示例#7
0
        static LogManager()
        {
            var layout = new SimpleLayout();
              layout.ActivateOptions();

              var logAppender = new EventLogAppender {Layout = layout, LogName = EventLogConstants.EVENT_LOG_NAME};
              logAppender.ActivateOptions();

              var lossyAppender = new BufferingForwardingAppender
              {
            Lossy = true,
            BufferSize = 10,
            Evaluator = new log4net.Core.LevelEvaluator(log4net.Core.Level.Error)
              };
              lossyAppender.AddAppender(logAppender);
              lossyAppender.ActivateOptions();

              var hierarchy = (Hierarchy) log4net.LogManager.GetRepository();
              Logger root = hierarchy.Root;

              root.Level = log4net.Core.Level.All;

              BasicConfigurator.Configure(lossyAppender);
        }
示例#8
0
文件: Logger.cs 项目: w3ttr3y/AppLog
        /// <summary>
        /// Configures a default configuration. This is used when <see cref="ConfigurationFile"/> is null so log4net will do something.
        /// </summary>
        /// <remarks>This default is to log everything to the eventlog.</remarks>
        protected void DefaultLocalConfiguration()
        {
            var pl = new PatternLayout { ConversionPattern = "%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" };
            pl.ActivateOptions();

            var e = new EventLogAppender {Layout = pl, ApplicationName = ApplicationName};
            e.ActivateOptions();

            log4net.Config.BasicConfigurator.Configure(e);
        }
 internal static EventLogAppender GetEventLogAppender(string logName, string applicationName)
 {
     var layout = new PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline");
     layout.ActivateOptions();
     var appender = new EventLogAppender
         {
             ApplicationName = applicationName,
             LogName = logName,
             Layout = layout,
         };
     appender.ActivateOptions();
     return appender;
 }
示例#10
0
            private static IAppender CreateEventLogAppender(string logName)
            {
                EventLogAppender appender = new EventLogAppender();
                appender.Layout = CreateOnlyMessageLayout();
                appender.ApplicationName = "AlarmWorkflow/" + logName;

                return appender;
            }
			/// <summary>
			/// Verifies that for each event log level, the correct system
			/// event log enumeration is returned
			/// </summary>
			[Test] public void TestGetEntryType()
			{
				EventLogAppender eventAppender = new EventLogAppender();

				Assertion.AssertEquals( 
					System.Diagnostics.EventLogEntryType.Information,
					eventAppender.GetEntryType( Level.ALL ) );

				Assertion.AssertEquals( 
					System.Diagnostics.EventLogEntryType.Information,
					eventAppender.GetEntryType( Level.DEBUG ) );

				Assertion.AssertEquals( 
					System.Diagnostics.EventLogEntryType.Information,
					eventAppender.GetEntryType( Level.INFO ) );

				Assertion.AssertEquals( 
					System.Diagnostics.EventLogEntryType.Warning,
					eventAppender.GetEntryType( Level.WARN ) );

				Assertion.AssertEquals( 
					System.Diagnostics.EventLogEntryType.Error,
					eventAppender.GetEntryType( Level.ERROR ) );

				Assertion.AssertEquals( 
					System.Diagnostics.EventLogEntryType.Error,
					eventAppender.GetEntryType( Level.FATAL ) );

				Assertion.AssertEquals( 
					System.Diagnostics.EventLogEntryType.Error,
					eventAppender.GetEntryType( Level.OFF ) );

			}
		//
		// Helper functions to dig into the appender
		//

		private static EventLogEntryType GetEntryType(EventLogAppender appender, Level level)
		{
			return (EventLogEntryType)Utils.InvokeMethod(appender, "GetEntryType", level);
		}
		//
		// Helper functions to dig into the appender
		//

		private static System.Diagnostics.EventLogEntryType GetEntryType(EventLogAppender appender, Level level)
		{
			return (System.Diagnostics.EventLogEntryType)Utils.InvokeMethod(appender, "GetEntryType", level);
		}
 public void ActivateOptionsDisablesAppenderIfSourceDoesntExist()
 {
     EventLogAppender eventAppender = new EventLogAppender();
     eventAppender.ActivateOptions();
     Assert.AreEqual(Level.Off, eventAppender.Threshold);
 }
示例#15
0
 private static EventLogAppender GetEventLogAppender(PatternLayout patternLayout)
 {
     EventLogAppender eventLogAppender = new EventLogAppender();
     eventLogAppender.LogName = EventLogName;
     eventLogAppender.ApplicationName = ApplicationName;
     eventLogAppender.Layout = patternLayout;
     eventLogAppender.Threshold = Level.Warn;
     eventLogAppender.ActivateOptions();
     return eventLogAppender;
 }
 // Configure the event log logger programmatically.
 public static void ConfigureEventLogAppender(ILog log, string sourceName, Level level)
 {
     bool isConfigured = log.Logger.Repository.GetAppenders().OfType<EventLogAppender>().Any();
     if (!isConfigured)
     {
         // Setup RollingFileAppender
         EventLogAppender appender = new EventLogAppender();
         appender.Layout = new log4net.Layout.PatternLayout(@"[%thread] - %message%newline");
         appender.ApplicationName = sourceName;
         appender.Name = "EventLogAppender";
         appender.Threshold = level;
         appender.ActivateOptions();
         BasicConfigurator.Configure(appender);
     }
 }