本文整理汇总了C#中Logger.LogException方法的典型用法代码示例。如果您正苦于以下问题:C# Logger.LogException方法的具体用法?C# Logger.LogException怎么用?C# Logger.LogException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Logger
的用法示例。
在下文中一共展示了Logger.LogException方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Log
/// <summary>
/// </summary>
/// <param name="logger"></param>
/// <param name="logItem"></param>
public static void Log(Logger logger, LogItem logItem)
{
if (!Constants.EnableNLog)
{
return;
}
switch (String.IsNullOrWhiteSpace(logItem.Message))
{
case true:
if (logItem.Exception == null)
{
return;
}
logger.LogException(logItem.LogLevel, logItem.Exception.Message, logItem.Exception);
break;
case false:
if (logItem.Exception == null)
{
logger.Log(logItem.LogLevel, logItem.Message);
}
else
{
logger.LogException(logItem.LogLevel, logItem.Message, logItem.Exception);
}
break;
}
}
示例2: Generate
/**
* Generates the system prefab from the configuration
* @return System prefab object
**/
public PSystem Generate()
{
// Dictionary of bodies generated
Dictionary<string, Body> bodies = new Dictionary<string, Body> ();
// Retrieve the root config node
ConfigNode rootConfig = GameDatabase.Instance.GetConfigs (rootNodeName) [0].config;
if (rootConfig.HasValue("Epoch"))
double.TryParse(rootConfig.GetValue("Epoch"), out Templates.instance.epoch);
if(rootConfig.HasValue("useOnDemand"))
bool.TryParse(rootConfig.GetValue("useOnDemand"), out OnDemand.OnDemandStorage.useOnDemand);
if (rootConfig.HasValue("onDemandLoadOnMissing"))
bool.TryParse(rootConfig.GetValue("onDemandLoadOnMissing"), out OnDemand.OnDemandStorage.onDemandLoadOnMissing);
if (rootConfig.HasValue("onDemandLogOnMissing"))
bool.TryParse(rootConfig.GetValue("onDemandLogOnMissing"), out OnDemand.OnDemandStorage.onDemandLogOnMissing);
if (rootConfig.HasValue("onDemandForceCollect"))
bool.TryParse(rootConfig.GetValue("onDemandForceCollect"), out OnDemand.OnDemandStorage.onDemandForceCollect);
if (rootConfig.HasNode("Finalize"))
foreach (ConfigNode n in rootConfig.GetNode("Finalize").GetNodes(bodyNodeName))
if (n.HasValue("name"))
Templates.instance.finalizeBodies.Add(n.GetValue("name"));
// Stage 1 - Load all of the bodies
foreach (ConfigNode bodyNode in rootConfig.GetNodes(bodyNodeName))
{
// Create a logger for this body
Logger bodyLogger = new Logger (bodyNode.GetValue ("name") + ".Body");
bodyLogger.SetAsActive ();
// Attempt to create the body
try
{
Body body = Parser.CreateObjectFromConfigNode<Body> (bodyNode);
bodies.Add (body.name, body);
Logger.Default.Log ("[Kopernicus]: Configuration.Loader: Loaded Body: " + body.name);
}
catch (Exception e)
{
bodyLogger.LogException (e);
Logger.Default.Log ("[Kopernicus]: Configuration.Loader: Failed to load Body: " + bodyNode.GetValue ("name"));
}
// Restore default logger
bodyLogger.Flush ();
Logger.Default.SetAsActive ();
}
// Stage 2 - create a new planetary system object
GameObject gameObject = new GameObject ("Kopernicus");
gameObject.transform.parent = Utility.Deactivator;
PSystem system = gameObject.AddComponent<PSystem> ();
// Set the planetary system defaults (pulled from PSystemManager.Instance.systemPrefab)
system.systemName = "Kopernicus";
system.systemTimeScale = 1.0;
system.systemScale = 1.0;
system.mainToolbarSelected = 2; // initial value in stock systemPrefab. Unknown significance.
// Stage 3 - Glue all the orbits together in the defined pattern
foreach (KeyValuePair<string, Body> body in bodies)
{
// If this body is in orbit around another body
if(body.Value.referenceBody != null)
{
// Get the Body object for the reference body
Body parent = null;
if(!bodies.TryGetValue(body.Value.referenceBody, out parent))
{
throw new Exception("\"" + body.Value.referenceBody + "\" not found.");
}
// Setup the orbit of the body
parent.generatedBody.children.Add(body.Value.generatedBody);
body.Value.generatedBody.orbitDriver.referenceBody = parent.generatedBody.celestialBody;
body.Value.generatedBody.orbitDriver.orbit.referenceBody = parent.generatedBody.celestialBody;
}
// Parent the generated body to the PSystem
body.Value.generatedBody.transform.parent = system.transform;
}
// Stage 4 - elect root body
system.rootBody = bodies.First(p => p.Value.referenceBody == null).Value.generatedBody;
// Stage 4.5, get the new Menu-body / Home body
if (rootConfig.HasValue("mainMenuBody"))
{
Templates.menuBody = rootConfig.GetValue("mainMenuBody");
}
else
{
Templates.menuBody = Utility.FindHomeBody(system.rootBody).name;
}
//.........这里部分代码省略.........
示例3: foreach
// Generates the system prefab from the configuration
void IParserEventSubscriber.PostApply(ConfigNode node)
{
// Dictionary of bodies generated
Dictionary<string, Body> bodies = new Dictionary<string, Body>();
// Load all of the bodies
foreach (ConfigNode bodyNode in node.GetNodes(bodyNodeName))
{
// Create a logger for this body
Logger bodyLogger = new Logger(bodyNode.GetValue("name") + ".Body");
bodyLogger.SetAsActive();
// Attempt to create the body
try
{
currentBody = new Body();
Parser.LoadObjectFromConfigurationNode(currentBody, bodyNode);
bodies.Add(currentBody.name, currentBody);
Logger.Default.Log("[Kopernicus]: Configuration.Loader: Loaded Body: " + currentBody.name);
}
catch (Exception e)
{
bodyLogger.LogException(e);
Logger.Default.Log("[Kopernicus]: Configuration.Loader: Failed to load Body: " + bodyNode.GetValue("name"));
}
// Restore default logger
bodyLogger.Flush ();
Logger.Default.SetAsActive ();
}
// Load all of the asteroids
foreach (ConfigNode asteroidNode in node.GetNodes(asteroidNodeName))
{
// Create a logger for this asteroid
Logger logger = new Logger(asteroidNode.GetValue("name") + ".Asteroid");
logger.SetAsActive();
// Attempt to create the Asteroid
try
{
Asteroid asteroid = Parser.CreateObjectFromConfigNode<Asteroid>(asteroidNode);
DiscoverableObjects.asteroids.Add(asteroid);
Logger.Default.Log("[Kopernicus]: Configuration.Loader: Loaded Asteroid: " + asteroid.name);
}
catch (Exception e)
{
logger.LogException(e);
Logger.Default.Log("[Kopernicus]: Configuration.Loader: Failed to load Asteroid: " + asteroidNode.GetValue("name"));
}
// Restore default logger
logger.Flush();
Logger.Default.SetAsActive();
}
// Glue all the orbits together in the defined pattern
foreach (KeyValuePair<string, Body> body in bodies)
{
// If this body is in orbit around another body
if(body.Value.orbit != null)
{
// Get the Body object for the reference body
Body parent = null;
if(!bodies.TryGetValue(body.Value.orbit.referenceBody, out parent))
{
throw new Exception("\"" + body.Value.orbit.referenceBody + "\" not found.");
}
// Setup the orbit of the body
parent.generatedBody.children.Add(body.Value.generatedBody);
body.Value.generatedBody.orbitDriver.referenceBody = parent.generatedBody.celestialBody;
body.Value.generatedBody.orbitDriver.orbit.referenceBody = parent.generatedBody.celestialBody;
}
// Parent the generated body to the PSystem
body.Value.generatedBody.transform.parent = systemPrefab.transform;
}
// Elect root body
systemPrefab.rootBody = bodies.First(p => p.Value.orbit == null).Value.generatedBody;
// Sort by distance from parent (discover how this effects local bodies)
RecursivelySortBodies (systemPrefab.rootBody);
// Fix doubled flightGlobals
List<int> numbers = new List<int>() { 0 };
int index = bodies.Sum(b => b.Value.generatedBody.flightGlobalsIndex);
PatchFGI(ref numbers, ref index, systemPrefab.rootBody);
// Main Menu bodies
if (randomMainMenuBodies.Any())
Templates.menuBody = randomMainMenuBodies[new System.Random().Next(0, randomMainMenuBodies.Count)];
}
示例4: Process
public static void Process(Logger logger,
IEnumerable<string> inPlaceFiles,
IEnumerable<string> templateFiles,
IEnumerable<string> templateIncludeFiles,
IEnumerable<string> templaceLibraryFiles,
IEnumerable<string> dependencyPaths,
string absoluteOutputDir,
out List<string> compileGeneratedFiles,
out List<string> embeddedResourceGeneratedFiles,
out List<string> filesToDelete,
bool createNewAppDomain,
bool debugMode,
string conditionalCompilationSymbols)
{
compileGeneratedFiles = new List<string>();
embeddedResourceGeneratedFiles = new List<string>();
filesToDelete = new List<string>();
try {
PreSharpGenerator generator = new PreSharpGenerator();
generator.Init(debugMode, logger, dependencyPaths, conditionalCompilationSymbols, absoluteOutputDir);
if (templaceLibraryFiles != null && templaceLibraryFiles.Any()) {
string libraryAssembly = Path.GetTempFileName();
File.Delete(libraryAssembly);
libraryAssembly = Path.ChangeExtension(libraryAssembly, ".dll");
if (generator.GenerateLibraryAssemblyFromTemplateLibraryFiles(templaceLibraryFiles, libraryAssembly, compileGeneratedFiles)) {
filesToDelete.Add(libraryAssembly);
generator.AddReference(libraryAssembly);
}
}
if (createNewAppDomain) {
AppDomain domain = AppDomain.CreateDomain("PreSharp Temporary Domain");
try {
PreSharpGenerator newGenerator = (PreSharpGenerator)domain.CreateInstanceFromAndUnwrap(
Assembly.GetExecutingAssembly().Location,
typeof(PreSharpGenerator).FullName);
newGenerator.Init(debugMode, logger, dependencyPaths, conditionalCompilationSymbols, absoluteOutputDir);
foreach (var reference in generator.References) {
newGenerator.AddReference(reference);
}
newGenerator.ProcessInplaceFiles(inPlaceFiles, compileGeneratedFiles);
newGenerator.ProcessTemplateFiles(templateFiles, templateIncludeFiles, compileGeneratedFiles, embeddedResourceGeneratedFiles);
} finally {
AppDomain.Unload(domain);
}
} else {
generator.ProcessInplaceFiles(inPlaceFiles, compileGeneratedFiles);
generator.ProcessTemplateFiles(templateFiles, templateIncludeFiles, compileGeneratedFiles, embeddedResourceGeneratedFiles);
}
} catch (Exception e) {
logger.LogException(null, e);
}
}