本文整理匯總了C#中NLog.Config.InstallationContext.CreateLogEvent方法的典型用法代碼示例。如果您正苦於以下問題:C# InstallationContext.CreateLogEvent方法的具體用法?C# InstallationContext.CreateLogEvent怎麽用?C# InstallationContext.CreateLogEvent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類NLog.Config.InstallationContext
的用法示例。
在下文中一共展示了InstallationContext.CreateLogEvent方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: RunInstallCommands
private void RunInstallCommands(InstallationContext installationContext, IEnumerable<DatabaseCommandInfo> commands)
{
// create log event that will be used to render all layouts
LogEventInfo logEvent = installationContext.CreateLogEvent();
try
{
foreach (var commandInfo in commands)
{
string cs;
if (commandInfo.ConnectionString != null)
{
// if there is connection string specified on the command info, use it
cs = commandInfo.ConnectionString.Render(logEvent);
}
else if (this.InstallConnectionString != null)
{
// next, try InstallConnectionString
cs = this.InstallConnectionString.Render(logEvent);
}
else
{
// if it's not defined, fall back to regular connection string
cs = this.BuildConnectionString(logEvent);
}
this.EnsureConnectionOpen(cs);
var command = this.activeConnection.CreateCommand();
command.CommandType = commandInfo.CommandType;
command.CommandText = commandInfo.Text.Render(logEvent);
try
{
installationContext.Trace("Executing {0} '{1}'", command.CommandType, command.CommandText);
command.ExecuteNonQuery();
}
catch (Exception exception)
{
if (exception.MustBeRethrown())
{
throw;
}
if (commandInfo.IgnoreFailures || installationContext.IgnoreFailures)
{
installationContext.Warning(exception.Message);
}
else
{
installationContext.Error(exception.Message);
throw;
}
}
}
}
finally
{
this.CloseConnection();
}
}