private void configureEntLib()
        {
            var formatterStandard = new FormatterBuilder().TextFormatterNamed("Text Formatter").UsingTemplate(
                "Timestamp: {timestamp}{newline}Message: {message}{newline}Severity: {severity}{newline}Machine: {machine}{newline}Process Name: {processName}{newline}Extended Properties: {dictionary({key} - {value}{newline})}");
            var conf      = new ConfigurationSourceBuilder();
            var logConfig = conf.ConfigureLogging();

            logConfig.WithOptions.LogToCategoryNamed("Exception").SendTo.RollingFile(
                "ExceptionFileListener").WithHeader("----------------------------------------").WithFooter("----------------------------------------").ToFile(UserContext.Settings.ExceptionsLogFile);
            logConfig.WithOptions.LogToCategoryNamed("General").SendTo.RollingFile(
                "FlatFile TraceListener").WithHeader("----------------------------------------").WithFooter("----------------------------------------").FormatWith(formatterStandard).ToFile(UserContext.Settings.StandardLogFile);
            logConfig.WithOptions.LogToCategoryNamed("email").SendTo.Email("email").FormatWith(formatterStandard).UsingSmtpServer(
                ApplicationSettings.MailSmtp).WithUserNameAndPassword(ApplicationSettings.MailUserName,
                                                                      ApplicationSettings.MailPassword).To(
                ApplicationSettings.MailAccount).From(
                ApplicationSettings.MailAccount).UseSSL(true);

            //configure cache
            var cacheCfg = conf.ConfigureCaching();

            cacheCfg.ForCacheManagerNamed(PicturesCache.PicturesCacheName).StoreInIsolatedStorage(
                "Isolated Storage Cache Store").UsePartition("PicturesCache1");

            cacheCfg.ForCacheManagerNamed("ErrorCache").StoreInMemory();

            var configSource = new DictionaryConfigurationSource();

            conf.UpdateConfigurationWithReplace(configSource);

            EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);

            BodyArchitect.Logger.Log.EnableExceptionLog = Settings1.Default.LogErrorEnabled;
            BodyArchitect.Logger.Log.EnableStandardLog  = Settings1.Default.LogStandardEnabled;
        }
        static internal void ClearLog()
        {
            string originalFileName = string.Format(@"C:\Logs\LogFileClearance.log");
            string tempFileName     = originalFileName.Replace(".log", "(TEMP).log");
            var    textFormatter    = new FormatterBuilder()
                                      .TextFormatterNamed("Custom Timestamped Text Formatter")
                                      .UsingTemplate("{timestamp(local:MM/dd/yy hh:mm:ss.fff tt)} tid={win32ThreadId}: {message}");

            #region Set the Logging LogWriter to use the temp file
            var builder = new ConfigurationSourceBuilder();

            builder.ConfigureLogging()
            .LogToCategoryNamed(INFO_CATEGORY).WithOptions.SetAsDefaultCategory()
            .SendTo.FlatFile("Flat File Trace Listener")
            .ToFile(tempFileName);

            using (DictionaryConfigurationSource configSource = new DictionaryConfigurationSource())
            {
                builder.UpdateConfigurationWithReplace(configSource);
                Marker.customLogWriter = new LogWriterFactory(configSource).Create();
            }
            InitializeLogger();
            #endregion

            #region Clear the original log file
            if (File.Exists(originalFileName))
            {
                File.WriteAllText(originalFileName, string.Empty);
            }
            #endregion

            #region Re-connect the original file to the log writer
            builder = new ConfigurationSourceBuilder();

            builder.ConfigureLogging()
            .WithOptions.DoNotRevertImpersonation()
            .LogToCategoryNamed(INFO_CATEGORY).WithOptions.SetAsDefaultCategory()
            .SendTo.RollingFile("Rolling Flat File Trace Listener")
            .RollAfterSize(1000)
            .FormatWith(textFormatter).WithHeader("").WithFooter("")
            .ToFile(originalFileName);

            using (DictionaryConfigurationSource configSource = new DictionaryConfigurationSource())
            {
                builder.UpdateConfigurationWithReplace(configSource);
                Marker.customLogWriter = new LogWriterFactory(configSource).Create();
            }
            InitializeLogger();
            #endregion
        }
예제 #3
0
 protected override void Arrange()
 {
     attributes.Add("key1", "value1");
     attributes.Add("key2", "value2");
     CustomFormatterBuilder = new FormatterBuilder().CustomFormatterNamed <MockLogFormatter>(CustomFormatterName, attributes);
 }
예제 #4
0
 protected override void Arrange()
 {
     CustomFormatterBuilder = new FormatterBuilder().CustomFormatterNamed <MockLogFormatter>(CustomFormatterName);
 }
예제 #5
0
 public void Setup()
 {
     streamFactory    = new Mock <IStreamFactory>();
     logger           = new Mock <ILog>();
     formatterBuilder = new FormatterBuilder(streamFactory.Object, logger.Object);
 }