本文整理汇总了C#中ILog.ErrorFormat方法的典型用法代码示例。如果您正苦于以下问题:C# ILog.ErrorFormat方法的具体用法?C# ILog.ErrorFormat怎么用?C# ILog.ErrorFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILog
的用法示例。
在下文中一共展示了ILog.ErrorFormat方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main( string[] args )
{
try{
_log = LogManager.GetCurrentClassLogger();
}catch(Exception ex ){
Console.WriteLine(ex.Message);
}
_log.InfoFormat("{0} ready to serve.", APP_NAME);
// BATCH
if (args.Length > 0) {
CodeRunner codeRunner = new CodeRunner();
try {
string padFile = args[0];
_log.InfoFormat("File argument: {0}", padFile);
// load configuration
PadConfig padConfig = new PadConfig();
if (!padConfig.Load(padFile)) {
_log.ErrorFormat("Error loading pad file!");
return;
}
// setup single factory (fast calls optimization)
if (padConfig.DataContext.Enabled) {
CustomConfiguration cfg = ServiceHelper.GetService<CustomConfiguration>();
cfg.FactoryRebuildOnTheFly = bool.FalseString;
cfg.IsConfigured = true;
}
// run
codeRunner.Build(padConfig);
codeRunner.Run();
} catch (Exception ex) {
_log.ErrorFormat(ex.Message);
} finally {
codeRunner.Release();
}
} else {
// GUI
try {
Application.Init();
SpoolPadWindow win = new SpoolPadWindow();
win.Show();
Application.Run();
} catch (Exception ex) {
MessageHelper.ShowError(ex);
}
}
_log.Info("SpoolPad goes to sleep.");
}
示例2: SendErrorEmail
private static void SendErrorEmail(string jobName, Exception ex, ILog log)
{
var username = CloudConfigurationManager.GetSetting("sendgrid-username");
var pass = CloudConfigurationManager.GetSetting("sendgrid-pass");
if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(pass))
{
log.Error("Could not send email notification. Check username or password settings");
}
try
{
var sgMessage = SendGrid.GetInstance();
sgMessage.From = new MailAddress("[email protected]", "Smithers Job Notifications");
sgMessage.Subject = "Smithers Error Notification";
sgMessage.AddTo("[email protected]");
sgMessage.Html = string.Format("Error: {0} failed at {1} with exception <strong>{2}</strong><br><br> {3}", jobName, ex.Source,
ex.Message, ex.StackTrace);
var transport = SMTP.GetInstance(new NetworkCredential(username, pass));
transport.Deliver(sgMessage);
}
catch (Exception mailException)
{
log.ErrorFormat("Error: Email send failed at {0} with exception {1} {2}", mailException,
mailException.Source, mailException.Message, mailException.StackTrace);
}
}
示例3: CallAllMethodsOnLog
protected void CallAllMethodsOnLog(ILog log)
{
Assert.IsTrue(log.IsDebugEnabled);
Assert.IsTrue(log.IsErrorEnabled);
Assert.IsTrue(log.IsFatalEnabled);
Assert.IsTrue(log.IsInfoEnabled);
Assert.IsTrue(log.IsWarnEnabled);
log.Debug("Testing DEBUG");
log.Debug("Testing DEBUG Exception", new Exception());
log.DebugFormat("Testing DEBUG With {0}", "Format");
log.Info("Testing INFO");
log.Info("Testing INFO Exception", new Exception());
log.InfoFormat("Testing INFO With {0}", "Format");
log.Warn("Testing WARN");
log.Warn("Testing WARN Exception", new Exception());
log.WarnFormat("Testing WARN With {0}", "Format");
log.Error("Testing ERROR");
log.Error("Testing ERROR Exception", new Exception());
log.ErrorFormat("Testing ERROR With {0}", "Format");
log.Fatal("Testing FATAL");
log.Fatal("Testing FATAL Exception", new Exception());
log.FatalFormat("Testing FATAL With {0}", "Format");
}
示例4: Initialize
public void Initialize(ISessionRegister sessionRegister)
{
m_SessionRegister = sessionRegister;
var appServer = AppContext.CurrentServer;
m_Log = appServer.Logger;
var config = appServer.Config;
if (!int.TryParse(config.Options.GetValue("handshakePendingQueueCheckingInterval"), out m_HandshakePendingQueueCheckingInterval))
{
m_HandshakePendingQueueCheckingInterval = 60;// 1 minute default
m_Log.ErrorFormat("Invalid configuration value handshakePendingQueueCheckingInterval");
}
if (!int.TryParse(config.Options.GetValue("openHandshakeTimeOut"), out m_OpenHandshakeTimeOut))
{
m_OpenHandshakeTimeOut = 120;// 2 minute default
m_Log.ErrorFormat("Invalid configuration value openHandshakeTimeOut");
}
}
示例5: Main
static int Main(string[] args)
{
var options = new Options();
ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(System.Console.Error));
if (!parser.ParseArguments(args, options))
{
System.Console.Error.WriteLine("Some of argumens are incorrect");
return IncorrectOptionsReturnCode;
}
LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter(options.Verbose ? LogLevel.Info: LogLevel.Warn, false, true, true, null);
log = LogManager.GetCurrentClassLogger();
var directoryPath = !string.IsNullOrWhiteSpace(options.BaseDirectory)? options.BaseDirectory: Environment.CurrentDirectory;
var baseDirectory = new DirectoryInfo(directoryPath);
if(!baseDirectory.Exists)
{
log.ErrorFormat("Provided directory {0} does not exist.", options.BaseDirectory);
return IncorrectOptionsReturnCode;
}
var url = new Lazy<Uri>(() => ParseDatabaseUrl(options));
if (options.Command == CommandType.Help)
System.Console.WriteLine(options.GetUsage());
else
try
{
ExecuteCommand(options.Command, baseDirectory, url, options.UserName, options.Password);
}
catch (Exception e)
{
log.ErrorFormat(e.ToString());
return UnknownErrorReturnCode;
}
return OkReturnCode;
}
示例6: LogFormat
public static void LogFormat(this IEnableLog This, ILog logger, LogType type, string format, params object[] args)
{
switch (type)
{
case LogType.Debug:
logger.DebugFormat(format, args);
break;
case LogType.Error:
logger.ErrorFormat(format, args);
break;
case LogType.Fatal:
logger.FatalFormat(format, args);
break;
case LogType.Info:
logger.InfoFormat(format, args);
break;
case LogType.Warn:
logger.WarnFormat(format, args);
break;
}
}
示例7: InternalTest
private static void InternalTest(ILog log)
{
const string message = "add record in db";
log.Debug(message);
log.Debug(message, new Exception());
log.DebugFormat(message);
log.Error(message);
log.Error(message, new Exception());
log.ErrorFormat(message);
log.Fatal(message);
log.Fatal(message, new Exception());
log.Info(message);
log.Info(message, new Exception());
log.InfoFormat(message);
log.Warn(message);
log.Warn(message, new Exception());
log.WarnFormat(message);
Console.WriteLine(log.IsDebugEnabled);
Console.WriteLine(log.IsErrorEnabled);
Console.WriteLine(log.IsFatalEnabled);
Console.WriteLine(log.IsInfoEnabled);
Console.WriteLine(log.IsWarnEnabled);
//log.TryLogFail(ErrorAction).Exception(e => Console.WriteLine(e.Message));
//log.TryLogFail(SuccessAction).Success(()=>{});
}
示例8: DefaultWriteLogEvent
protected static void DefaultWriteLogEvent(ILog commonLog, TraceEventType traceEventType, String message, Exception ex)
{
switch (traceEventType)
{
case TraceEventType.Critical:
commonLog.FatalFormat(message, ex);
break;
case TraceEventType.Error:
commonLog.ErrorFormat(message, ex);
break;
case TraceEventType.Warning:
commonLog.WarnFormat(message, ex);
break;
case TraceEventType.Information:
commonLog.InfoFormat(message, ex);
break;
case TraceEventType.Verbose:
commonLog.TraceFormat(message, ex);
break;
case TraceEventType.Start:
commonLog.DebugFormat(message, ex);
break;
case TraceEventType.Stop:
commonLog.DebugFormat(message, ex);
break;
case TraceEventType.Suspend:
commonLog.DebugFormat(message, ex);
break;
case TraceEventType.Resume:
commonLog.DebugFormat(message, ex);
break;
case TraceEventType.Transfer:
commonLog.DebugFormat(message, ex);
break;
default:
throw new ArgumentOutOfRangeException("traceEventType");
}
}
示例9: CanLogMessageWithException
protected virtual void CanLogMessageWithException(ILog log)
{
log.TraceFormat("Hi {0}", new ArithmeticException(), "dude");
log.DebugFormat("Hi {0}", new ArithmeticException(), "dude");
log.InfoFormat("Hi {0}", new ArithmeticException(), "dude");
log.WarnFormat("Hi {0}", new ArithmeticException(), "dude");
log.ErrorFormat("Hi {0}", new ArithmeticException(), "dude");
log.FatalFormat("Hi {0}", new ArithmeticException(), "dude");
}
示例10: Main
public static void Main (String[] args, ILog logger)
{
if (args.Length == 0) {
logger.Error("GC bridge: No test specified");
return;
}
GcBridge.logger = logger;
Bridge.fin_count = 0;
var benchmark = args[0];
switch (benchmark) {
case "gcbridge-links":
RunTest(SetupLinks);
break;
case "gcbridge-linkedfan":
RunTest(SetupLinkedFan);
break;
case "gcbridge-inversefan":
RunTest(SetupInverseFan);
break;
case "gcbridge-deadlist":
RunTest(SetupDeadList);
break;
case "gcbridge-selflinks":
RunTest(SetupSelfLinks);
break;
case "gcbridge-spider":
RunTest(Spider);
break;
case "gcbridge-doublefan-1000":
DFAN_OUT = 1000;
RunTest(SetupDoubleFan);
break;
case "gcbridge-doublefan-4000":
DFAN_OUT = 4000;
RunTest(SetupDoubleFan);
break;
default:
logger.ErrorFormat("GC bridge: Unknown test {0}", benchmark);
break;
}
}
示例11: DoWithRetry
public static void DoWithRetry(uint maxAttempts, string description, Action op, ILog logger,
double retryIntervalBaseSecs = 5, Action error = null,
Func<Exception, bool> retryHandler = null)
{
retryIntervalBaseSecs = Math.Max(1, retryIntervalBaseSecs);
var triesLeft = maxAttempts;
int whichAttempt = 0;
Exception ex = null;
if (retryHandler == null)
retryHandler = GenericRetryHandler;
var timer = new Stopwatch();
while (triesLeft-- > 0)
{
timer.Start();
var delay = (int)Math.Min(1800, Math.Pow(retryIntervalBaseSecs, whichAttempt++));
try
{
logger.InfoFormat("operation starting: {0} attempt {1}", description, whichAttempt);
op();
timer.Stop();
logger.InfoFormat("{0} completed after {1} attempts and {2}ms", description, whichAttempt, timer.ElapsedMilliseconds);
return;
}
catch (WebServiceException exc)
{
bool allowRetry = retryHandler(exc);
int statusCode = exc.StatusCode;
string message = exc.ErrorMessage;
ex = HandleException(description, logger, allowRetry, whichAttempt, delay, message, exc, statusCode, timer);
}
catch (WebException exc)
{
bool allowRetry = retryHandler(exc);
int statusCode = 0;
string message = exc.ToString();
if (exc.Response != null)
{
var wr = ((HttpWebResponse)exc.Response);
statusCode = (int)wr.StatusCode;
message = wr.StatusDescription;
}
ex = HandleException(description, logger, allowRetry, whichAttempt, delay, message, exc, statusCode, timer);
}
catch (OperationCanceledException)
{
timer.Stop();
logger.ErrorFormat("Operation canceled exception: {0}, do not retry, ran for {1}ms", description, timer.ElapsedMilliseconds);
return;
}
catch (Exception exc)
{
ex = HandleException(description, logger, true, whichAttempt, delay, exc.ToString(), exc, 0, timer); ;
}
}
if (ex != null)
{
if (timer.IsRunning)
{
timer.Stop();
}
if (error != null)
error();
throw new ApplicationException(string.Format("Maximum retries exceeded, total time {0}ms", timer.ElapsedMilliseconds) , ex);
}
}
示例12: HandleException
private static Exception HandleException(string description, ILog logger, bool allowRetry, int whichAttempt, int delay,
string message, Exception exc, int statusCode, Stopwatch timer)
{
if (allowRetry)
{
logger.ErrorFormat("Error while {0}, attempt {1}, elapsed {4}ms, retrying in {2} seconds: \r\n{3}", description,
whichAttempt, delay, message, timer.ElapsedMilliseconds);
System.Threading.Thread.Sleep(1000 * delay);
return exc;
}
else
{
timer.Stop();
logger.ErrorFormat("HTTP Response code {0} : {1}, elapsed time {2}ms", statusCode, exc, timer.ElapsedMilliseconds);
var code = HttpStatusCode.InternalServerError;
Enum.TryParse(statusCode.ToString(), out code);
throw new BaseSpaceException(code, message, exc);
}
}