本文整理汇总了C#中Logger.ErrorException方法的典型用法代码示例。如果您正苦于以下问题:C# Logger.ErrorException方法的具体用法?C# Logger.ErrorException怎么用?C# Logger.ErrorException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Logger
的用法示例。
在下文中一共展示了Logger.ErrorException方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
log = LogManager.GetCurrentClassLogger();
log.Info("Version: {0}", RocksmithToolkitLib.ToolkitVersion.version);
log.Info("OS: {0}", Environment.OSVersion.ToString());
log.Info("Command: {0}", Environment.CommandLine.ToString());
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
{
var exception = (Exception)e.ExceptionObject;
MessageBox.Show(String.Format("Application.ThreadException\n{0}\n{1}\nPlease send us \"_RSToolkit_{2}.log\", you can find it in Toolkit folder.",
exception.ToString(), exception.Message.ToString(), DateTime.Now.ToString("yyyy-MM-dd")), "Unhandled Exception catched!");
log.ErrorException(String.Format("\n{0}\n{1}\nException catched:\n{2}\n", exception.Source, exception.TargetSite, exception.InnerException), exception);
};
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// UI thread exceptions handling.
Application.ThreadException += (s, e) =>
{
var exception = (Exception)e.Exception;
MessageBox.Show(String.Format("Application.ThreadException\n{0}\n{1}\nPlease send us \"_RSToolkit_{2}.log\", you can find it in Toolkit folder.",
exception.ToString(), exception.Message.ToString(), DateTime.Now.ToString("yyyy-MM-dd")), "Thread Exception catched!");
log.ErrorException(String.Format("\n{0}\n{1}\nException catched:\n{2}\n", exception.Source, exception.TargetSite, exception.InnerException), exception);
};
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Application.Run(new MainForm(args));
}
示例2: Main
static void Main(string[] args)
{
Log = LogManager.GetCurrentClassLogger();
Log.Info(
String.Format("Version: {0} ({1} bit)\r\n ", RocksmithToolkitLib.ToolkitVersion.version, Environment.Is64BitProcess ? "64" : "32") +
String.Format("OS: {0} ({1} bit)\r\n ", Environment.OSVersion, Environment.Is64BitOperatingSystem ? "64" : "32") +
String.Format("Runtime: v{0}\r\n ", Environment.Version) +
String.Format("JIT: {0}", JitVersionInfo.GetJitVersion())
);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
{
var exception = (Exception)e.ExceptionObject;
MessageBox.Show(String.Format("Application.ThreadException\n{0}\n{1}\nPlease send us \"_RSToolkit_{2}.log\", you can find it in Toolkit folder.",
exception.ToString(), exception.Message.ToString(), DateTime.Now.ToString("yyyy-MM-dd")), "Unhandled Exception catched!");
Log.ErrorException(String.Format("\n{0}\n{1}\nException catched:\n{2}\n", exception.Source, exception.TargetSite, exception.InnerException), exception);
};
// UI thread exceptions handling.
Application.ThreadException += (s, e) =>
{
var exception = (Exception)e.Exception;
MessageBox.Show(String.Format("Application.ThreadException\n{0}\n{1}\nPlease send us \"_RSToolkit_{2}.log\", you can find it in Toolkit folder.",
exception.ToString(), exception.Message.ToString(), DateTime.Now.ToString("yyyy-MM-dd")), "Thread Exception catched!");
Log.ErrorException(String.Format("\n{0}\n{1}\nException catched:\n{2}\n", exception.Source, exception.TargetSite, exception.InnerException), exception);
};
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm(args));
}
示例3: Main
static void Main()
{
Logger = LoggingFactory.BuildLogger();
try
{
using (var service = new Program())
{
if (Environment.UserInteractive)
{
service.OnStart(null);
Console.WriteLine("Press any key to stop program");
Console.Read();
service.OnStop();
}
else
{
Run(service);
}
}
}
catch (Exception exception)
{
Logger.ErrorException("Failed to start ", exception);
}
finally
{
//TODO: hack to make nlog work with mono. remove when nlog is updated
LogManager.Configuration = null;
}
}
示例4: InstallerForm
public InstallerForm(PluginPackageInfo pluginPackageInfo, Logger logger)
: this()
{
_logger = logger;
try
{
_pluginPackageInfo = pluginPackageInfo;
_studioVersionService = new StudioVersionService(_pluginPackageInfo);
_installService = new InstallService(_pluginPackageInfo);
}
catch (Exception exception)
{
_logger.ErrorException("Error constructing installer window",exception);
throw;
}
}
示例5: Application_Start
protected void Application_Start()
{
try
{
log = LogManager.GetCurrentClassLogger();
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
log.Trace("Application was started");
}
catch (Exception e)
{
log.ErrorException("Exeption during start application: " + e.Message, e);
}
}
示例6: WorkerRole
public WorkerRole(Settings settings)
{
string logDir = Path.Combine(Environment.CurrentDirectory, "Logs");
try
{
// Configure NLog
LoggingConfiguration config = new LoggingConfiguration();
// Console Target
var consoleTarget = new SnazzyConsoleTarget();
config.AddTarget("console", consoleTarget);
consoleTarget.Layout = "[${logger:shortName=true}] ${message}";
// Get the logs resource if it exists and use it as the log dir
try
{
if (RoleEnvironment.IsAvailable)
{
LocalResource logsResource = RoleEnvironment.GetLocalResource("Logs");
logDir = logsResource.RootPath;
}
}
catch (Exception)
{
// Just use basedir.
}
// File Target
FileTarget jobLogTarget = new FileTarget()
{
FileName = Path.Combine(logDir, "Jobs", "${logger:shortName=true}.${date:yyyy-MM-dd}.log.json"),
};
ConfigureFileTarget(jobLogTarget);
config.AddTarget("file", jobLogTarget);
FileTarget hostTarget = new FileTarget()
{
FileName = Path.Combine(logDir, "Host", "Host.${date:yyyy-MM-dd}.log")
};
ConfigureFileTarget(hostTarget);
config.AddTarget("file", hostTarget);
LoggingRule allMessagesToConsole = new LoggingRule("*", NLog.LogLevel.Trace, consoleTarget);
config.LoggingRules.Add(allMessagesToConsole);
// All other rules transfer all kinds of log messages EXCEPT Trace.
LoggingRule hostToFile = new LoggingRule("JobRunner", NLog.LogLevel.Debug, hostTarget);
config.LoggingRules.Add(hostToFile);
LoggingRule roleToFile = new LoggingRule("WorkerRole", NLog.LogLevel.Debug, hostTarget);
config.LoggingRules.Add(roleToFile);
LoggingRule jobLogs = new LoggingRule("Job.*", NLog.LogLevel.Debug, jobLogTarget);
config.LoggingRules.Add(jobLogs);
LogManager.Configuration = config;
_logger = LogManager.GetLogger("WorkerRole");
}
catch (Exception ex)
{
File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FatalError.txt"), ex.ToString());
}
_logger.Info("Logging Enabled to {0}", logDir);
try
{
if (RoleEnvironment.IsAvailable)
{
ConfigureAzureDiagnostics(logDir);
}
else
{
_logger.Info("Skipping Azure Diagnostics, we aren't in Azure");
}
}
catch (Exception ex)
{
_logger.InfoException("Skipping Azure Diagnostics, we got an exception trying to check if we are in Azure", ex);
}
try
{
_runner = LoadJobRunner(settings);
}
catch (Exception ex)
{
_logger.ErrorException("Error loading Job Runner", ex);
}
}
示例7: ExecuteScript
private static void ExecuteScript(UserScript script, ScriptHost scriptHost, Logger logger, object[] args)
{
try
{
//var engine = new JScriptEngine(WindowsScriptEngineFlags.EnableDebugging);
var engine = new JScriptEngine();
engine.AddHostObject("host", scriptHost);
string initArgsScript = string.Format("var arguments = {0};", args.ToJson());
engine.Execute(initArgsScript);
engine.Execute(script.Body);
}
catch (Exception ex)
{
var messge = string.Format("Error in user script {0}", script.Name);
logger.ErrorException(messge, ex);
}
}
示例8: CreativeModule
public CreativeModule(Framework framework, IDocumentStore documentStore, AddCreativeCommand addCreativeCommand, Logger logger)
: base("/creative")
{
Post["/send"] = call =>
{
var model = this.Bind<ServiceEndpoints.Creative.Send>();
framework.ExecuteTask(new CreateCreativeFragmentsTask
{
CreativeId = model.CreativeId,
});
return Response.AsText("OK");
};
Post["/save"] = call =>
{
var model = this.Bind<ServiceEndpoints.Creative.SaveCreative>();
addCreativeCommand.HtmlBody = model.HtmlBody;
addCreativeCommand.TextBody = model.TextBody;
addCreativeCommand.Lists = new List<string> { model.ListId };
addCreativeCommand.Subject = model.Subject;
addCreativeCommand.UnsubscribeTemplateId = model.UnsubscribeTemplateId;
addCreativeCommand.DealUrl = model.DealUrl;
addCreativeCommand.FromName = model.FromName;
addCreativeCommand.FromAddressDomainPrefix = model.FromAddressDomainPrefix;
var creativeId = addCreativeCommand.Execute();
return Response.AsJson(new ApiStringResult { Result = creativeId });
};
Get["/getall"] = call =>
{
using (var session = documentStore.OpenSession())
{
return Response.AsJson(session.Query<Creative>().Customize(x => x.WaitForNonStaleResults()).ToList());
}
};
Get["/fragments"] = call =>
{
var model = this.Bind<ServiceEndpoints.Creative.FetchFragment>();
using (var session = documentStore.OpenSession())
{
var creativeFragmentId = "";
session.Advanced.UseOptimisticConcurrency = true;
while (true)
{
try
{
var creativeFragment = session.Query<CreativeFragment>()
.Customize(x => x.WaitForNonStaleResults(TimeSpan.FromMinutes(5)))
.Where(x => x.Status == FragmentStatus.Pending)
.ToList()
.FirstOrDefault();
if (creativeFragment == null)
{
logger.Info("No fragments were found");
return null;
}
creativeFragmentId = creativeFragment.Id;
creativeFragment.Status = FragmentStatus.Sending;
creativeFragment.FetchedBy = model.DroneId;
creativeFragment.FetchedAt = DateTime.UtcNow;
session.Store(creativeFragment);
session.SaveChanges();
logger.Info("creative was found with id {0} it has {1} contacts inside", creativeFragment.Id, creativeFragment.Recipients.Count);
return Response.AsJson(creativeFragment);
}
catch (ConcurrencyException ex)
{
logger.ErrorException(string.Format("While fetching creative fragment: {0} we had a cuncurrency error", creativeFragmentId), ex);
}
}
}
};
Get["/clone"] = _ =>
{
var creativeId = (string)Request.Query["creativeId"];
var listId = (string)Request.Query["listId"];
using (var session = documentStore.OpenSession())
{
var creative = session.Load<Creative>(creativeId);
if (creative == null)
return "Error";
session.Advanced.Evict(creative);
creative.Id = null;
creative.Lists.Clear();
creative.Lists.Add(listId);
//.........这里部分代码省略.........
示例9: Main
static void Main(string[] args)
{
switch(AppConfigOptions.DIContainer)
{
case DIContainer.Ninject:
{
throw new NotSupportedException("Ninject is no longer supported");
//var kernel = new StandardKernel(new NinjectModules.SrirachaNinjectorator());
//_logger = kernel.Get<NLog.Logger>();
//_diFactory = kernel.Get<IDIFactory>();
}
//break;
case DIContainer.Autofac:
{
try
{
var builder = new ContainerBuilder();
builder.RegisterModule(new SrirachaAutofacorator(EnumDIMode.Service));
builder.RegisterType<WinService>().AsSelf();
var container = builder.Build();
_logger = container.Resolve<NLog.Logger>();
_diFactory = container.Resolve<IDIFactory>();
}
catch(ReflectionTypeLoadException err)
{
foreach(var loaderError in err.LoaderExceptions)
{
Console.WriteLine("LOADER EXCEPTION: " + loaderError.ToString());
}
throw;
}
}
break;
default:
throw new UnknownEnumValueException(AppConfigOptions.DIContainer);
}
SetupColorConsoleLogging();
var options = new CommandLineOptions();
if(!Parser.Default.ParseArguments(args, options))
{
throw new Exception(options.GetUsage());
}
if(!string.IsNullOrWhiteSpace(options.WorkingDirectory))
{
var settings = _diFactory.CreateInjectedObject<ISystemSettings>();
settings.DeployWorkingDirectory = options.WorkingDirectory;
}
if(!string.IsNullOrEmpty(options.RunDeploymentId))
{
var deploymentBatchRunner = _diFactory.CreateInjectedObject<IDeployBatchRunner>();
deploymentBatchRunner.ForceRunDeployment(options.RunDeploymentId);
}
else if (options.CleanupFolders)
{
var job = _diFactory.CreateInjectedObject<IFolderCleanupJob>();
job.ForceRun();
}
else if (options.CreateOfflineDeployment)
{
var job = _diFactory.CreateInjectedObject<IOfflineDeploymentPackageJob>();
job.RunNow();
}
else if (options.Debug)
{
Console.WriteLine("\t-Starting in debug mode...");
try
{
var service = _diFactory.CreateInjectedObject<WinService>();
service.DebugStart(options.ThrashMode);
}
catch(Exception err)
{
_logger.ErrorException("Debug mode failed: " + err.ToString(), err);
}
finally
{
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
else
{
var service = _diFactory.CreateInjectedObject<WinService>();
ServiceBase.Run(service);
}
}