本文整理汇总了C#中NLog.Layouts.SimpleLayout.Render方法的典型用法代码示例。如果您正苦于以下问题:C# SimpleLayout.Render方法的具体用法?C# SimpleLayout.Render怎么用?C# SimpleLayout.Render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NLog.Layouts.SimpleLayout
的用法示例。
在下文中一共展示了SimpleLayout.Render方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleLayoutCachingTest
public void SimpleLayoutCachingTest()
{
var l = new SimpleLayout("xx${level}yy");
var ev = LogEventInfo.CreateNullEvent();
string output1 = l.Render(ev);
string output2 = l.Render(ev);
Assert.AreSame(output1, output2);
}
示例2: LayoutRendererThrows
public void LayoutRendererThrows()
{
ConfigurationItemFactory configurationItemFactory = new ConfigurationItemFactory();
configurationItemFactory.LayoutRenderers.RegisterDefinition("throwsException", typeof(ThrowsExceptionRenderer));
SimpleLayout l = new SimpleLayout("xx${throwsException}yy", configurationItemFactory);
string output = l.Render(LogEventInfo.CreateNullEvent());
Assert.AreEqual("xxyy", output);
}
示例3: Append
protected override void Append(StringBuilder builder, LogEventInfo logEvent)
{
if (!_isCached)
{
_cachedValue = GetValue();
}
var layout = new SimpleLayout(_cachedValue);
builder.Append(layout.Render(logEvent));
}
示例4: Start
private static void Start( string[ ] args )
{
//register object builder assembly
string path = System.IO.Path.Combine( AppDomain.CurrentDomain.BaseDirectory, "SpaceEngineers.ObjectBuilders.DLL" );
VRage.Plugins.MyPlugins.RegisterGameObjectBuildersAssemblyFile( path );
MyObjectBuilderType.RegisterAssemblies( );
//Setup error handling for unmanaged exceptions
AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException;
Application.ThreadException += Application_ThreadException;
Application.SetUnhandledExceptionMode( UnhandledExceptionMode.CatchException );
//AppDomain.CurrentDomain.ClearEventInvocations("_unhandledException");
BaseLog.Info( "Starting SEServerExtender with {0} arguments: {1}", args.Length, string.Join( "\r\n\t", args ) );
CommandLineArgs extenderArgs = CommandLineArgs = new CommandLineArgs
{
ConsoleTitle = string.Empty,
AutoStart = false,
WorldName = string.Empty,
InstanceName = string.Empty,
NoGui = false,
NoConsole = false,
Debug = false,
GamePath = new DirectoryInfo( PathManager.BasePath ).Parent.FullName,
NoWcf = false,
Autosave = 0,
InstancePath = string.Empty,
CloseOnCrash = false,
RestartOnCrash = false,
Args = string.Join( " ", args.Select( x => string.Format( "\"{0}\"", x ) ) )
};
if ( ConfigurationManager.AppSettings[ "WCFChatMaxMessageHistoryAge" ] != null )
if ( !int.TryParse( ConfigurationManager.AppSettings[ "WCFChatMaxMessageHistoryAge" ], out _maxChatHistoryMessageAge ) )
{
ConfigurationManager.AppSettings.Add( "WCFChatMaxMessageHistoryAge", "3600" );
}
if ( ConfigurationManager.AppSettings[ "WCFChatMaxMessageHistoryCount" ] != null )
if ( !int.TryParse( ConfigurationManager.AppSettings[ "WCFChatMaxMessageHistoryCount" ], out _maxChatHistoryMessageCount ) )
{
ConfigurationManager.AppSettings.Add( "WCFChatMaxMessageHistoryCount", "100" );
}
bool logPathSet = false;
//Process the args
foreach ( string arg in args )
{
string[ ] splitAtEquals = arg.Split( '=' );
if ( splitAtEquals.Length > 1 )
{
string argName = splitAtEquals[ 0 ];
string argValue = splitAtEquals[ 1 ];
string lowerCaseArgument = argName.ToLower( );
if ( lowerCaseArgument.Equals( "instance" ) )
{
if ( argValue[ argValue.Length - 1 ] == '"' )
argValue = argValue.Substring( 1, argValue.Length - 2 );
extenderArgs.InstanceName = argValue;
//Only let this override log path if the log path wasn't already explicitly set
if ( !logPathSet )
{
FileTarget baseLogTarget = LogManager.Configuration.FindTargetByName( "BaseLog" ) as FileTarget;
if ( baseLogTarget != null )
{
baseLogTarget.FileName = baseLogTarget.FileName.Render( new LogEventInfo { TimeStamp = DateTime.Now } ).Replace( "NoInstance", argValue );
}
FileTarget chatLogTarget = LogManager.Configuration.FindTargetByName( "ChatLog" ) as FileTarget;
if ( chatLogTarget != null )
{
chatLogTarget.FileName = chatLogTarget.FileName.Render( new LogEventInfo { TimeStamp = DateTime.Now } ).Replace( "NoInstance", argValue );
}
FileTarget pluginLogTarget = LogManager.Configuration.FindTargetByName( "PluginLog" ) as FileTarget;
if ( pluginLogTarget != null )
{
pluginLogTarget.FileName = pluginLogTarget.FileName.Render( new LogEventInfo { TimeStamp = DateTime.Now } ).Replace( "NoInstance", argValue );
}
}
}
else if ( lowerCaseArgument.Equals( "gamepath" ) )
{
if ( argValue[ argValue.Length - 1 ] == '"' )
argValue = argValue.Substring( 1, argValue.Length - 2 );
extenderArgs.GamePath = argValue;
}
else if ( lowerCaseArgument.Equals( "autosave" ) )
{
if ( !int.TryParse( argValue, out extenderArgs.Autosave ) )
BaseLog.Warn( "Autosave parameter was not a valid integer." );
}
else if ( lowerCaseArgument.Equals( "path" ) )
{
if ( argValue[ argValue.Length - 1 ] == '"' )
argValue = argValue.Substring( 1, argValue.Length - 2 );
extenderArgs.InstancePath = argValue;
}
//.........这里部分代码省略.........
示例5: Evaluate
/// <summary>
/// Evaluates the specified text by expadinging all layout renderers.
/// </summary>
/// <param name="text">The text to be evaluated.</param>
/// <param name="logEvent">Log event to be used for evaluation.</param>
/// <returns>The input text with all occurences of ${} replaced with
/// values provided by the appropriate layout renderers.</returns>
public static string Evaluate(string text, LogEventInfo logEvent)
{
var l = new SimpleLayout(text);
return l.Render(logEvent);
}
示例6: LayoutRendererThrows2
public void LayoutRendererThrows2()
{
string internalLogOutput = RunAndCaptureInternalLog(
() =>
{
ConfigurationItemFactory configurationItemFactory = new ConfigurationItemFactory();
configurationItemFactory.LayoutRenderers.RegisterDefinition("throwsException", typeof(ThrowsExceptionRenderer));
SimpleLayout l = new SimpleLayout("xx${throwsException:msg1}yy${throwsException:msg2}zz", configurationItemFactory);
string output = l.Render(LogEventInfo.CreateNullEvent());
Assert.AreEqual("xxyyzz", output);
},
LogLevel.Warn);
Assert.IsTrue(internalLogOutput.IndexOf("msg1") >= 0, internalLogOutput);
Assert.IsTrue(internalLogOutput.IndexOf("msg2") >= 0, internalLogOutput);
}
示例7: LayoutRendererThrows
public void LayoutRendererThrows()
{
NLogFactories nlogFactories = new NLogFactories();
nlogFactories.LayoutRendererFactory.RegisterDefinition("throwsException", typeof(ThrowsExceptionRenderer));
SimpleLayout l = new SimpleLayout("xx${throwsException}yy", nlogFactories);
string output = l.Render(LogEventInfo.CreateNullEvent());
Assert.AreEqual("xxyy", output);
}
示例8: Start
private static void Start( string[ ] args )
{
// SE_VERSION is a private constant. Need to use reflection to get it.
FieldInfo field = typeof(SpaceEngineersGame).GetField("SE_VERSION", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
SeVersion = new Version(new MyVersion((int)field.GetValue(null)).FormattedText.ToString().Replace("_", "."));
bool stableBuild = (bool)typeof(MyFinalBuildConstants).GetField("IS_STABLE").GetValue(null);
ApplicationLog.BaseLog.Info($"SE version: {SeVersion}");
ApplicationLog.BaseLog.Info( $"Extender version: {Assembly.GetExecutingAssembly().GetName().Version}" );
if (stableBuild)
{
BaseLog.Info("Detected \"Stable\" branch!");
IsStable = true;
PluginManager.IsStable = true;
//hide the block limit config, since it will crash in stable
HideConfigs();
}
else
BaseLog.Info("Detected \"Development\" branch!");
InitSandbox(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory + @"..\Content"), Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SpaceEngineers"));
//Setup error handling for unmanaged exceptions
AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException;
Application.ThreadException += Application_ThreadException;
Application.SetUnhandledExceptionMode( UnhandledExceptionMode.CatchException );
//AppDomain.CurrentDomain.ClearEventInvocations("_unhandledException");
BaseLog.Info( "Starting SEServerExtender with {0} arguments: {1}", args.Length, string.Join( "\r\n\t", args ) );
CommandLineArgs extenderArgs = CommandLineArgs = new CommandLineArgs
{
ConsoleTitle = string.Empty,
AutoStart = false,
WorldName = string.Empty,
InstanceName = string.Empty,
NoGui = false,
NoConsole = false,
Debug = false,
GamePath = new DirectoryInfo( PathManager.BasePath ).Parent.FullName,
//TODO: turn noWFC back to off by default whenever WCF gets fixed
NoWcf = true,
Autosave = 0,
InstancePath = string.Empty,
CloseOnCrash = false,
RestartOnCrash = false,
NoProfiler = false,
Args = string.Join( " ", args.Select( x => string.Format( "\"{0}\"", x ) ) )
};
if ( ConfigurationManager.AppSettings[ "WCFChatMaxMessageHistoryAge" ] != null )
if ( !int.TryParse( ConfigurationManager.AppSettings[ "WCFChatMaxMessageHistoryAge" ], out _maxChatHistoryMessageAge ) )
{
ConfigurationManager.AppSettings.Add( "WCFChatMaxMessageHistoryAge", "3600" );
}
if ( ConfigurationManager.AppSettings[ "WCFChatMaxMessageHistoryCount" ] != null )
if ( !int.TryParse( ConfigurationManager.AppSettings[ "WCFChatMaxMessageHistoryCount" ], out _maxChatHistoryMessageCount ) )
{
ConfigurationManager.AppSettings.Add( "WCFChatMaxMessageHistoryCount", "100" );
}
bool logPathSet = false;
//Process the args
foreach ( string arg in args )
{
string[ ] splitAtEquals = arg.Split( '=' );
if ( splitAtEquals.Length > 1 )
{
string argName = splitAtEquals[ 0 ];
string argValue = splitAtEquals[ 1 ];
string lowerCaseArgument = argName.ToLower( );
if ( lowerCaseArgument.Equals( "instance" ) )
{
if ( argValue[ argValue.Length - 1 ] == '"' )
argValue = argValue.Substring( 1, argValue.Length - 2 );
//sanitize input because stupid people put full paths for this argument
extenderArgs.InstanceName = argValue.Replace( @"\", "-" ).Replace( @":", "-" );
//Only let this override log path if the log path wasn't already explicitly set
if ( !logPathSet )
{
FileTarget baseLogTarget = LogManager.Configuration.FindTargetByName( "BaseLog" ) as FileTarget;
if ( baseLogTarget != null )
{
baseLogTarget.FileName = baseLogTarget.FileName.Render(new LogEventInfo { TimeStamp = DateTime.Now }).Replace("NoInstance", argValue.Replace(@"\", "-").Replace(@":", "-"));
}
FileTarget chatLogTarget = LogManager.Configuration.FindTargetByName( "ChatLog" ) as FileTarget;
if ( chatLogTarget != null )
{
chatLogTarget.FileName = chatLogTarget.FileName.Render(new LogEventInfo { TimeStamp = DateTime.Now }).Replace("NoInstance", argValue.Replace(@"\", "-").Replace(@":", "-"));
}
FileTarget pluginLogTarget = LogManager.Configuration.FindTargetByName( "PluginLog" ) as FileTarget;
if ( pluginLogTarget != null )
{
pluginLogTarget.FileName = pluginLogTarget.FileName.Render(new LogEventInfo { TimeStamp = DateTime.Now }).Replace("NoInstance", argValue.Replace(@"\", "-").Replace(@":", "-"));
//.........这里部分代码省略.........