本文整理汇总了C#中log4net.Layout.PatternLayout.ActivateOptions方法的典型用法代码示例。如果您正苦于以下问题:C# PatternLayout.ActivateOptions方法的具体用法?C# PatternLayout.ActivateOptions怎么用?C# PatternLayout.ActivateOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类log4net.Layout.PatternLayout
的用法示例。
在下文中一共展示了PatternLayout.ActivateOptions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public static void Configure()
{
var hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Root.RemoveAllAppenders();
// see http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html
var layout = new PatternLayout
{
ConversionPattern = "%date{dd-MMM-yyyy HH:mm:ss} %-5level %message%n%exception%n"
};
var fileAppender = new RollingFileAppender
{
Layout = layout,
AppendToFile = true,
File = "log.txt",
LockingModel = new FileAppender.MinimalLock(),
};
var consoleAppender = new ConsoleAppender
{
Layout = layout,
};
layout.ActivateOptions();
fileAppender.ActivateOptions();
log4net.Config.BasicConfigurator.Configure(fileAppender);
consoleAppender.ActivateOptions();
log4net.Config.BasicConfigurator.Configure(consoleAppender);
}
示例2: CrearAppenderFichero
/// <summary>
/// Contiene la logica para crear un appender FICHERO
/// </summary>
/// <param name="nombreAppender">Nombre del appender</param>
/// <param name="nombreFichero">Nombre del fichero</param>
/// <param name="patronConversion"> Si se deja a null el valor por defecto es %d [%t] %-5p %c [%x] - %m%n </param>
/// <returns>Retorna el appender creado</returns>
public static IAppender CrearAppenderFichero(string nombreAppender, string nombreFichero, string patronConversion)
{
var appender = new FileAppender
{
Name = nombreAppender,
File = nombreFichero,
AppendToFile = true
};
var patronConversionAux = "%d [%t] %-5p %c [%x] - %m%n";
if(patronConversion != null && !patronConversion.Equals(string.Empty))
{
patronConversionAux = patronConversion;
}
var layout = new PatternLayout
{
ConversionPattern = patronConversionAux
};
layout.ActivateOptions();
appender.Layout = layout;
appender.ActivateOptions();
return appender;
}
示例3: RegisterTypes
public static void RegisterTypes(IUnityContainer container)
{
var hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Root.RemoveAllAppenders();
hierarchy.Root.Level = Level.Debug;
hierarchy.RaiseConfigurationChanged(EventArgs.Empty);
FileAppender fileAppender = new RollingFileAppender();
fileAppender.AppendToFile = true;
fileAppender.LockingModel = new FileAppender.MinimalLock();
fileAppender.File = HttpContext.Current.Server.MapPath("~/TestHarness1.log.txt");
var patternLayout = new PatternLayout { ConversionPattern = "%d [%2%t] %-5p [%-10c] %m%n%n" };
patternLayout.ActivateOptions();
fileAppender.Layout = patternLayout;
fileAppender.ActivateOptions();
BasicConfigurator.Configure(fileAppender);
var logger = LogManager.GetLogger(typeof(IServiceBus));
container.RegisterInstance<ILog>(logger, new ContainerControlledLifetimeManager());
var ftpClient = new FtpQueueClient();
ftpClient.ConnectAsync(new Uri("ftp://ftp.jdibble.co.uk/site1/Personal/service-bus-ftp/queue"), new NetworkCredential("jdibble-001", "jli798ik")).Wait();
container.RegisterInstance<IFtpQueueClient>(ftpClient, new ContainerControlledLifetimeManager());
container.RegisterType<IQueueManager, FtpQueueManager>(new ContainerControlledLifetimeManager());
container.RegisterType<SharedMessageHandler>();
var messageDictionary = new MessageTypeDictionary
{
{ ServiceBus.Messaging.MessageExtensions.MessageTypeSignature<SharedMessage>(), typeof(SharedMessage) },
{ ServiceBus.Messaging.MessageExtensions.MessageTypeSignature<NonSharedMessage>(), typeof(NonSharedMessage) },
{ ServiceBus.Messaging.MessageExtensions.MessageTypeSignature<SharedEvent>(), typeof(SharedEvent) }
};
container.RegisterInstance<IMessageSerialiser>(new JsonMessageSerialiser(messageDictionary), new ContainerControlledLifetimeManager());
var serviceBus =
ServiceBusBuilder.Configure()
.WithLogger(container.Resolve<ILog>())
.WithHostAddress(new Uri("http://servicebus-ftp.jdibble.co.uk"))
.WithHttpTransport(new JsonMessageSerialiser(messageDictionary))
.AsMvcServiceBus(RouteTable.Routes, container.Resolve<IQueueManager>())
.Build()
.WithMessageHandler(container.Resolve<SharedMessageHandler>())
.Subscribe(container.Resolve<SharedEventHandler>())
.WithPeerAsync(new Peer(new Uri("http://servicebus-ftp2.jdibble.co.uk"))).Result;
serviceBus.WithPeerAsync(new Peer(new Uri("http://servicebus.jdibble.co.uk")));
serviceBus.WithPeerAsync(new Peer(new Uri("http://servicebus2.jdibble.co.uk")));
container.RegisterInstance(serviceBus, new ContainerControlledLifetimeManager());
container.RegisterType<ServiceBusHub>(new ContainerControlledLifetimeManager());
}
示例4: Setup
public static void Setup(string path)
{
var hierarchy = (Hierarchy)LogManager.GetRepository();
var patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
// patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
patternLayout.ActivateOptions();
var roller = new RollingFileAppender();
roller.AppendToFile = true;
roller.File = path;
roller.Layout = patternLayout;
roller.MaxSizeRollBackups = 5;
roller.MaximumFileSize = "2MB";
roller.RollingStyle = RollingFileAppender.RollingMode.Size;
roller.StaticLogFileName = true;
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
var memory = new MemoryAppender();
memory.ActivateOptions();
hierarchy.Root.AddAppender(memory);
hierarchy.Root.Level = Level.Info;
hierarchy.Configured = true;
}
示例5: Configure
/// <summary>
/// Configures the <see cref="FileLogger"/> logger adding the appenders
/// to the root repository.
/// </summary>
public void Configure() {
// create a new logger into the repository of the current assembly.
ILoggerRepository root_repository =
LogManager.GetRepository(Assembly.GetExecutingAssembly());
Logger nohros_console_logger =
root_repository.GetLogger("NohrosConsoleLogger") as Logger;
// create the layout and appender for on error messages.
PatternLayout layout = new PatternLayout();
layout.ConversionPattern = layout_pattern_;
layout.ActivateOptions();
// create the appender
ConsoleAppender appender = new ConsoleAppender();
appender.Name = "NohrosCommonConsoleAppender";
appender.Layout = layout;
appender.Target = "Console.Out";
appender.Threshold = Level.All;
appender.ActivateOptions();
nohros_console_logger.Parent.AddAppender(appender);
root_repository.Configured = true;
logger = LogManager.GetLogger("NohrosConsoleLogger");
}
示例6: CreateLogger
private void CreateLogger(String name, String conversionPattern)
{
// Create Appender
var nameWDate = name + "_" + _time;
var path = (_path.Equals(""))
? @"Logs\" + _date + @"\" + _time.Replace(':', '_') + @"\" + name + ".log"
: _path + _date + @"\" + _time.Replace(':', '_') + @"\" + name + ".log";
var appender = new RollingFileAppender()
{
Name = nameWDate,
File = path,
AppendToFile = true
};
// Create Layout
var layout = new PatternLayout() {ConversionPattern = conversionPattern};
layout.ActivateOptions();
// Apply Layout to Appender
appender.Layout = layout;
appender.ActivateOptions();
// Create Logger
var logger = LogManager.GetLogger(nameWDate);
// Apply Appender to Logger
((log4net.Repository.Hierarchy.Logger) logger.Logger).AddAppender(appender);
// Add Logger to Dictionary
_loggers.Add(name, logger);
XmlConfigurator.Configure();
}
示例7: ConfigureLog4Net
public static void ConfigureLog4Net()
{
var layout = new PatternLayout
{
ConversionPattern = "%d [%t] %-5p %c [%x] - %m%n"
};
layout.ActivateOptions();
var consoleAppender = new ColoredConsoleAppender
{
Threshold = Level.Debug,
Layout = layout
};
consoleAppender.ActivateOptions();
var appender = new RollingFileAppender
{
DatePattern = "yyyy-MM-dd'.txt'",
RollingStyle = RollingFileAppender.RollingMode.Composite,
MaxFileSize = 10 * 1024 * 1024,
MaxSizeRollBackups = 10,
LockingModel = new FileAppender.MinimalLock(),
StaticLogFileName = false,
File = @"nsb_log_",
Layout = layout,
AppendToFile = true,
Threshold = Level.Debug,
};
appender.ActivateOptions();
BasicConfigurator.Configure(appender, consoleAppender);
}
示例8: set_file_appender
public static void set_file_appender(string output_directory)
{
if (!already_configured_file_appender)
{
already_configured_file_appender = true;
var layout = new PatternLayout
{
ConversionPattern = "%date [%-5level] - %message%newline"
};
layout.ActivateOptions();
var rollingFileAppender = new RollingFileAppender
{
Name = "roundhouse.changes.log.appender",
File = Path.Combine(Path.GetFullPath(output_directory), "roundhouse.changes.log"),
Layout = layout,
AppendToFile = false
};
rollingFileAppender.ActivateOptions();
var log = LogManager.GetLogger("roundhouse");
var logger = (log4net.Repository.Hierarchy.Logger)log.Logger;
logger.AddAppender(rollingFileAppender);
var nhLog = LogManager.GetLogger("NHibernate.SQL");
var nhLogger = (log4net.Repository.Hierarchy.Logger)nhLog.Logger;
nhLogger.AddAppender(rollingFileAppender);
}
}
示例9: Configure
public void Configure()
{
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Root.RemoveAllAppenders(); /*Remove any other appenders*/
FileAppender fileAppender = new FileAppender();
fileAppender.AppendToFile = true;
fileAppender.LockingModel = new FileAppender.MinimalLock();
fileAppender.File = _locationProvider.GetFilePath();
PatternLayout pl = new PatternLayout();
pl.ConversionPattern = "%d [%2%t] %-5p [%-10c] %m%n%n";
pl.ActivateOptions();
fileAppender.Layout = pl;
fileAppender.ActivateOptions();
ConsoleAppender consoleAppender = new ConsoleAppender();
consoleAppender.Layout = pl;
consoleAppender.ActivateOptions();
// log4net.Config.BasicConfigurator.Configure(fileAppender);
IAppender[] appenders = {fileAppender, consoleAppender};
log4net.Config.BasicConfigurator.Configure(appenders);
var log = LogManager.GetLogger(GetType());
log.Debug("Logging Configured");
}
示例10: Setup
public static void Setup(string path)
{
// "%d[%2%t] %-5p[%-10c] %m %n"
var pl = new PatternLayout {ConversionPattern = "%c%m%n"};
pl.ActivateOptions();
var fileAppender = new FileAppender
{
AppendToFile = true,
LockingModel = new FileAppender.MinimalLock(),
File = path,
Layout = pl
};
fileAppender.ActivateOptions();
var bufferingForwardingAppender = new BufferingForwardingAppender
{
Lossy = false,
Fix = FixFlags.None
};
bufferingForwardingAppender.AddAppender(fileAppender);
bufferingForwardingAppender.ActivateOptions();
var consoleAppender = new ConsoleAppender {Layout = pl};
consoleAppender.ActivateOptions();
var hierarchy = (Hierarchy) LogManager.GetRepository();
hierarchy.Root.RemoveAllAppenders();
BasicConfigurator.Configure(hierarchy, bufferingForwardingAppender, consoleAppender);
}
示例11: CreateFileAppender
// Create a new file appender
public static RollingFileAppender CreateFileAppender(LoggerConfigurationElement element)
{
var appender = new RollingFileAppender();
appender.Name = element.LoggerName;
appender.File = element.Filename;
appender.AppendToFile = true;
appender.RollingStyle = RollingFileAppender.RollingMode.Composite;
appender.MaximumFileSize = element.MaximumFileSize;
appender.MaxSizeRollBackups = element.MaxSizeRollBackups;
appender.PreserveLogFileNameExtension = element.PreserveLogFileNameExtension;
appender.DatePattern = element.DatePattern;
var layout = new PatternLayout();
layout.ConversionPattern = "%message";
layout.ActivateOptions();
var filter = new LoggerMatchFilter();
filter.LoggerToMatch = element.LoggerName;
filter.ActivateOptions();
var denyAllFilter = new DenyAllFilter();
denyAllFilter.ActivateOptions();
appender.AddFilter(filter);
appender.AddFilter(denyAllFilter);
appender.Layout = layout;
appender.ActivateOptions();
return appender;
}
示例12: InitLog4net
private static void InitLog4net()
{
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "[%date] %-5level [%thread] %property{user} - %message%exception%n";
patternLayout.ActivateOptions();
RollingFileAppender roller = new RollingFileAppender();
roller.AppendToFile = true;
roller.File = @"logs\";
roller.Layout = patternLayout;
roller.MaxSizeRollBackups = 100;
roller.MaximumFileSize = "10MB";
roller.RollingStyle = RollingFileAppender.RollingMode.Date;
roller.DatePattern = "yyyyMMdd'.log'";
roller.StaticLogFileName = false;
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
hierarchy.Root.Level = Level.All;
hierarchy.Configured = true;
log4net.GlobalContext.Properties["user"] = new Log4NetUserNameProvider();
}
示例13: Logger
static Logger()
{
var hierarchy = (Hierarchy)LogManager.GetRepository();
var tracer = new TraceAppender();
var patternLayout = new PatternLayout {ConversionPattern = LOG_PATTERN};
patternLayout.ActivateOptions();
tracer.Layout = patternLayout;
tracer.ActivateOptions();
hierarchy.Root.AddAppender(tracer);
var roller = new RollingFileAppender
{
Layout = patternLayout,
AppendToFile = true,
RollingStyle = RollingFileAppender.RollingMode.Size,
MaxSizeRollBackups = 4,
MaximumFileSize = "10240KB",
StaticLogFileName = true,
File = FilePath + @"\f1speed-log.txt"
};
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
hierarchy.Root.Level = Level.Debug;
hierarchy.Configured = true;
}
示例14: DefaultLogWrapper
public DefaultLogWrapper(string logname, IConfig config)
{
this.logname = logname;
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
hierarchy.Clear();
TraceAppender tracer = new TraceAppender();
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%t (%-5level) - %m%n";
patternLayout.ActivateOptions();
tracer.Layout = patternLayout;
tracer.ActivateOptions();
hierarchy.Root.AddAppender(tracer);
RollingFileAppender roller = new RollingFileAppender();
roller.Layout = patternLayout;
roller.AppendToFile = true;
roller.RollingStyle = RollingFileAppender.RollingMode.Size;
roller.MaxSizeRollBackups = 4;
roller.MaximumFileSize = "100KB";
roller.StaticLogFileName = true;
roller.File = Path.Combine(config.IndexFolder, "totalrecall-" + this.logname + ".log");
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
hierarchy.Root.Level = Level.All;
hierarchy.Configured = true;
}
示例15: SetPath
public void SetPath(String path)
{
//_writer = new StreamWriter(path);
//_path = path;
PatternLayout patternLayout = new PatternLayout
{
ConversionPattern = "[%date] - [%logger] - %level - %message%newline"
};
patternLayout.ActivateOptions();
RollingFileAppender rollingFileAppender = new RollingFileAppender
{
File = path,
Layout = patternLayout,
MaximumFileSize = "5MB",
MaxSizeRollBackups = 2,
PreserveLogFileNameExtension = true,
RollingStyle = RollingFileAppender.RollingMode.Size,
LockingModel = new FileAppender.MinimalLock()
};
rollingFileAppender.ActivateOptions();
Hierarchy hierarchy = LogManager.GetRepository() as Hierarchy;
Logger root = hierarchy.Root;
root.RemoveAllAppenders();
root.Level = Level.All;
BasicConfigurator.Configure(rollingFileAppender);
}