本文整理汇总了C#中log4net.Appender.ConsoleAppender类的典型用法代码示例。如果您正苦于以下问题:C# ConsoleAppender类的具体用法?C# ConsoleAppender怎么用?C# ConsoleAppender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConsoleAppender类属于log4net.Appender命名空间,在下文中一共展示了ConsoleAppender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConfigureLog4Net
private static void ConfigureLog4Net()
{
if (ConfigurationManager.GetSection("log4net") == null)
{
var layout = new SimpleLayout();
layout.ActivateOptions();
var consoleAppender = new ConsoleAppender
{
Layout = layout
};
consoleAppender.AddFilter(new LevelRangeFilter
{
LevelMin = Level.Info,
LevelMax = Level.Fatal,
AcceptOnMatch = false
});
consoleAppender.AddFilter(
new LoggerMatchFilter
{
LoggerToMatch = "Remora",
AcceptOnMatch = true
}
);
consoleAppender.AddFilter(new DenyAllFilter());
consoleAppender.ActivateOptions();
BasicConfigurator.Configure(consoleAppender);
}
else
{
XmlConfigurator.Configure();
}
}
示例2: ConfigureLogging
static void ConfigureLogging()
{
var consoleAppender = new ConsoleAppender();
consoleAppender.Layout = new PatternLayout("[%date{yyyy-MM-dd HH:mm:ss}] %-5p %c{1} - %m%n");
BasicConfigurator.Configure(consoleAppender);
}
示例3: 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);
}
示例4: 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");
}
示例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: Main
public static void Main(string[] args)
{
ConsoleAppender consoleAppender = new ConsoleAppender();
consoleAppender.Layout =
new PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline");
log4net.Config.BasicConfigurator.Configure(consoleAppender);
if (args.Length == 0)
{
m_log.Debug("Please specify filename");
return;
}
Program webApp = new Program();
//string myStr = "<!--#include file=\"content-box.html\" -->";
//string result = Processor.Processor.Process(myStr);
//m_log.Debug(result);
string fileName = args[0];
using (StreamReader sr = new StreamReader(fileName))
{
string content = sr.ReadToEnd();
Processor p = new Processor(webApp, null);
string result = p.Process(content);
m_log.Debug(result);
}
}
示例7: Setup
public static void Setup()
{
Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
PatternLayout patternLayout = new PatternLayout();
patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
patternLayout.ActivateOptions();
RollingFileAppender roller = new RollingFileAppender();
roller.AppendToFile = false;
roller.File = @"Logs\EventLog.txt";
roller.Layout = patternLayout;
roller.MaxSizeRollBackups = 5;
roller.MaximumFileSize = "1GB";
roller.RollingStyle = RollingFileAppender.RollingMode.Size;
roller.StaticLogFileName = true;
roller.ActivateOptions();
hierarchy.Root.AddAppender(roller);
ConsoleAppender appender = new ConsoleAppender();
appender.Layout = patternLayout;
appender.ActivateOptions();
hierarchy.Root.AddAppender(appender);
MemoryAppender memory = new MemoryAppender();
memory.ActivateOptions();
hierarchy.Root.AddAppender(memory);
hierarchy.Root.Level = Level.Debug;
hierarchy.Configured = true;
}
示例8: Main
public static void Main(string[] args)
{
var consoleAppender = new ConsoleAppender()
{
Layout = new PatternLayout("%message%newline"),
Threshold = Level.Info
};
log4net.Config.BasicConfigurator.Configure(consoleAppender);
var log = LogManager.GetLogger(typeof(SlnFileGenerator));
var fileGenerator = new SlnFileGenerator();
var optionsBuilder = new ArgsOptionsBuilder();
var options = optionsBuilder.Build(args, Directory.GetCurrentDirectory());
if (options.ShowHelp)
{
optionsBuilder.WriteHelpMessage();
return;
}
consoleAppender.Threshold = options.LoggingThreshold;
var solutionPath = fileGenerator.GenerateSolutionFile(options);
if (options.OpenInVisualStudio)
{
log.InfoFormat("Opening {0} in Visual Studio {1}", solutionPath, options.VisualStudioVersion.Year);
VisualStudioIntegration.OpenSolution(solutionPath, options.VisualStudioVersion);
}
}
示例9: 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);
}
示例10: ConfigureLogging
static void ConfigureLogging(ServerOptions options)
{
var layout = new PatternLayout("%date %level - %message%newline");
layout.ActivateOptions();
var appenders = new List<IAppender>();
if (!string.IsNullOrEmpty(options.LogFileDirectory))
{
var fileAppender = new FileAppender
{
Layout = layout,
Encoding = Encoding.UTF8,
File = Path.Combine(options.LogFileDirectory, "orchestrion.log"),
AppendToFile = true,
LockingModel = new FileAppender.MinimalLock(),
ImmediateFlush = true,
};
fileAppender.ActivateOptions();
appenders.Add(fileAppender);
}
if (options.ConsoleOutput)
{
var consoleAppender = new ConsoleAppender
{
Layout = layout
};
consoleAppender.ActivateOptions();
appenders.Add(consoleAppender);
}
BasicConfigurator.Configure(appenders.ToArray());
}
示例11: BindConsole
public static void BindConsole(PatternLayout layout = null, Level level = null)
{
layout = layout ?? new PatternLayout
{
ConversionPattern = "%date{ISO8601} %level %logger - %message%newline"
};
layout.ActivateOptions();
var consoleAppender = new ConsoleAppender
{
Name = "console",
Layout = layout
};
consoleAppender.ActivateOptions();
var hierarchy = (Hierarchy)LogManager.GetRepository();
if (hierarchy.Root.GetAppender("console") != null)
{
return;
}
hierarchy.Root.AddAppender(consoleAppender);
hierarchy.Root.Level = level ?? Level.Info;
hierarchy.Configured = true;
}
示例12: LogToConsole
public static void LogToConsole()
{
ConsoleAppender consoleAppender = new ConsoleAppender();
consoleAppender.Layout =
new PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline");
log4net.Config.BasicConfigurator.Configure(consoleAppender);
}
示例13: AddConsoleLogger
public static void AddConsoleLogger()
{
ConsoleAppender consoleLog = new ConsoleAppender();
PatternLayout patternLayout = new PatternLayout(config.PatternFormat);
consoleLog.Layout = patternLayout;
AddAppender(consoleLog);
}
示例14: SetUpFixture
public void SetUpFixture()
{
Util.LogLog.InternalDebugging = true;
Hierarchy hierarchy = (Hierarchy) LogManager.GetRepository();
PatternLayout patternLayout = new PatternLayout { ConversionPattern = "%d [%t] %-5p %m%n" };
patternLayout.ActivateOptions();
TraceAppender tracer = new TraceAppender { Layout = patternLayout };
tracer.ActivateOptions();
hierarchy.Root.AddAppender(tracer);
ConsoleAppender console = new ConsoleAppender
{
Name = "console",
Layout = patternLayout,
Target = "Console.Out",
Threshold = Level.All,
};
console.ActivateOptions();
hierarchy.Root.AddAppender(console);
RollingFileAppender rollingFile = new RollingFileAppender
{
Name = "file",
Layout = patternLayout,
AppendToFile = true,
RollingStyle = RollingFileAppender.RollingMode.Size,
MaxSizeRollBackups = 4,
MaximumFileSize = "100KB",
StaticLogFileName = true,
LockingModel = new FileAppender.MinimalLock(),
File = "logs\\logFile.txt",
};
rollingFile.ActivateOptions();
hierarchy.Root.AddAppender(rollingFile);
RollbarAppender rollbar = new RollbarAppender
{
Name = "rollbar",
Layout = patternLayout,
AccessToken = "3203880e148b43b4b1a14430fb41957a",
Threshold = Level.Notice,
};
rollbar.ActivateOptions();
hierarchy.Root.AddAppender(rollbar);
hierarchy.Root.Level = Level.All;
hierarchy.Configured = true;
}
示例15: DataTests
static DataTests()
{
var layout = new PatternLayout("%-6timestamp %-5level - %message%newline");
var appender = new ConsoleAppender { Layout = layout };
layout.ActivateOptions();
appender.ActivateOptions();
BasicConfigurator.Configure(appender);
}