本文整理匯總了C#中System.Log.Info方法的典型用法代碼示例。如果您正苦於以下問題:C# Log.Info方法的具體用法?C# Log.Info怎麽用?C# Log.Info使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Log
的用法示例。
在下文中一共展示了Log.Info方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WriteMessagesWithUnIndent
public void WriteMessagesWithUnIndent()
{
LogManager.RegisterDebugListener();
var log = new Log(typeof(int));
LogMessageEventArgs eventArgs = null;
log.LogMessage += (sender, e) => eventArgs = e;
log.Indent();
log.Info("Indented message");
log.Unindent();
log.Info("Unindented message");
Assert.IsNotNull(eventArgs);
Assert.AreEqual(log, eventArgs.Log);
Assert.AreEqual(LogEvent.Info, eventArgs.LogEvent);
Assert.AreEqual("[System.Int32] Unindented message", eventArgs.Message);
}
示例2: ActivateDataset
/// <summary>
/// Activates the dataset with the given ID.
/// </summary>
/// <param name="application">The application.</param>
/// <param name="log">The log object.</param>
/// <param name="id">The ID of the dataset that should be activated.</param>
public static void ActivateDataset(Application application, Log log, int id)
{
const string prefix = "Project page - Activate dataset";
if (IsDatasetActivated(application, log, id))
{
log.Info(
prefix,
"Dataset is already activated.");
return;
}
var tab = TabProxies.GetProjectPageTabItem(application, log);
if (tab == null)
{
throw new RegressionTestFailedException(prefix + " - Failed to get project tab.");
}
var datasets = GetDatasetControls(application, log);
if (datasets.Count == 0)
{
throw new RegressionTestFailedException(prefix + " - Failed to get dataset controls.");
}
if (!datasets.ContainsKey(id))
{
throw new RegressionTestFailedException(prefix + " - Failed to find dataset with id: " + id.ToString(CultureInfo.InvariantCulture));
}
var buttonId = string.Format(
CultureInfo.InvariantCulture,
"Button_[{0}_[DatasetId: [{1}]]]",
DatasetViewAutomationIds.DatasetActivateDeactivate,
id);
var buttonSearchCriteria = SearchCriteria
.ByAutomationId(buttonId);
var button = tab.Get<Button>(buttonSearchCriteria);
if (button == null)
{
throw new RegressionTestFailedException(prefix + " - Failed to get activate dataset button.");
}
try
{
button.Click();
}
catch (Exception e)
{
throw new RegressionTestFailedException(prefix + " - Failed to activate the dataset.", e);
}
// handle dialog
SelectMachineForDatasetActivation(application, log);
// Wait for the dataset to be activated
WaitForDatasetActivation(application, log, id);
}
示例3: FindItemManuallyInUIContainer
/// <summary>
/// Manually searches for a <see cref="UIItem"/> in a container.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="automationId">The automation ID for the control.</param>
/// <param name="log">The log object.</param>
/// <returns>The control if it can be found; otherwise, <see langword="null" />.</returns>
public static IUIItem FindItemManuallyInUIContainer(UIItemContainer container, string automationId, Log log)
{
const string logPrefix = "Controls - Find element manually";
log.Debug(
logPrefix,
string.Format(
CultureInfo.InvariantCulture,
"Searching for UI element with ID: [{0}].",
automationId));
if ((container == null) || string.IsNullOrEmpty(automationId))
{
return null;
}
var stack = new Stack<UIItemContainer>();
stack.Push(container);
while (stack.Count > 0)
{
var localContainer = stack.Pop();
foreach (var element in localContainer.Items)
{
log.Debug(
logPrefix,
string.Format(
CultureInfo.InvariantCulture,
"Found UI item of type [{0}] with ID: [{1}]. Name: [{2}]",
element.GetType().Name,
element.Id,
element.Name));
if (string.Equals(element.Id, automationId, StringComparison.Ordinal))
{
log.Info(
logPrefix,
string.Format(
CultureInfo.InvariantCulture,
"Found desired element of type [{0}] with ID: [{1}]",
element.GetType().Name,
element.Id));
return element;
}
var subContainer = element as UIItemContainer;
if (subContainer != null)
{
stack.Push(subContainer);
}
}
}
return null;
}
示例4: ExitApplication
public static void ExitApplication(Application application, Log log)
{
const string prefix = "Application - Exit";
if (application != null)
{
log.Info(prefix, "Closing application.");
try
{
application.Close();
if (application.Process.HasExited)
{
return;
}
application.Process.WaitForExit(Constants.ShutdownWaitTimeInMilliSeconds());
if (!application.Process.HasExited)
{
application.Kill();
}
}
catch (InvalidOperationException)
{
// Do nothing because the cause for this exception is when there is no process
// associated with the application.Process object.
}
catch (Exception e)
{
log.Error(
prefix,
string.Format(
CultureInfo.InvariantCulture,
"Error trying to terminate application. Error was: {0}",
e));
}
}
}
示例5: FindApolloInstallDirectoryInDevelopmentLocation
private static string FindApolloInstallDirectoryInDevelopmentLocation(Log log)
{
var buildDirectory = Constants.GetPathOfExecutingScript();
if (!string.IsNullOrEmpty(buildDirectory))
{
// Move down the directory structure to find the final file
var explorerFiles = Directory.GetFiles(buildDirectory, Constants.GetApolloExplorerFileName(), SearchOption.AllDirectories);
if (explorerFiles.Length == 1)
{
log.Info(
"Application - Search development directory",
string.Format(
CultureInfo.InvariantCulture,
"Found apollo explorer at [{0}].",
buildDirectory));
return Path.GetDirectoryName(explorerFiles[0]);
}
}
return null;
}
示例6: VerifyViewMenu
/// <summary>
/// Verifies that the 'View' menu works as expected.
/// </summary>
/// <param name="application">The application.</param>
/// <param name="log">The log object.</param>
/// <returns>The test result for the current test case.</returns>
public TestResult VerifyViewMenu(Application application, Log log)
{
const string prefix = "View menu";
var result = new TestResult();
var assert = new Assert(result, log);
try
{
var startPage = TabProxies.GetStartPageTabItem(application, log);
if (startPage != null)
{
log.Info(prefix, "Closing start page.");
TabProxies.CloseStartPageTab(application, log);
}
// Make sure we don't close the welcome tab upon opening the project page
WelcomePageControlProxies.UncheckCloseWelcomePageOnProjectOpen(application, log);
var projectPage = TabProxies.GetProjectPageTabItem(application, log);
if (projectPage != null)
{
log.Info(prefix, "Closing project page.");
TabProxies.CloseProjectPageTab(application, log);
}
// Open start page via view menu
MenuProxies.SwitchToStartPageViaViewStartPageMenuItem(application, log);
startPage = TabProxies.GetStartPageTabItem(application, log);
assert.IsNotNull(startPage, prefix + " - Check start page exists after clicking start page menu item");
assert.IsTrue(startPage.IsSelected, prefix + " - Check start page is focussed after clicking start page menu item");
}
catch (RegressionTestFailedException e)
{
var message = string.Format(
CultureInfo.InvariantCulture,
"Failed with exception. Error: {0}",
e);
log.Error(prefix, message);
result.AddError(prefix + " - " + message);
}
return result;
}
示例7: TestConcurrency
public void TestConcurrency()
{
// start up the next log instance
var queue = new Loggers.Queue();
var props = new List<String>()
{
"Http.Uri",
"Http.Path",
"Http.Method",
"Http.StatusCode",
"Http.Status",
"Http.Timestamp",
"Http.User",
"Http.SessionID",
"Http.IPAddress",
"Http.Request.TestHeader",
"Http.Session.TestVariable"
};
using (
Log.RegisterInstance(
new Instance()
{
Logger = queue,
Synchronous = false,
Buffer = 0,
Properties = props
}
)
)
{
Log log = new Log(GetType());
Parallel.For(0, TestParallelIterations,
i =>
{
HttpContext.Current = MockHttp.CreateHttpContext();
log.Info("test");
}
);
Log.Flush();
// verify event properties
for (Int32 i = 0; i < TestParallelIterations; i++)
{
var evt = queue.Dequeue().First();
Assert.AreEqual(evt["Http.Uri"], "http://www.tempuri.org/?Test=Value");
Assert.AreEqual(evt["Http.Path"], "/?Test=Value");
Assert.AreEqual(evt["Http.Method"], "HEAD");
Assert.AreEqual(evt["Http.StatusCode"], 200);
Assert.AreEqual(evt["Http.Status"], "200 OK");
Assert.IsTrue((DateTime)evt["Http.Timestamp"] <= DateTime.Now);
Assert.AreEqual(evt["Http.User"], "testuser");
Assert.IsNotNull(evt["Http.SessionID"]);
Assert.AreEqual(evt["Http.IPAddress"], Dns.GetHostAddresses("localhost")[0].ToString());
Assert.AreEqual(evt["Http.Request.TestHeader"], "TestHeaderValue");
Assert.AreEqual(evt["Http.Session.TestVariable"], "TestVariableValue");
}
Assert.IsFalse(queue.Dequeue().Any());
}
}
示例8: StartApplication
/// <summary>
/// Starts the application.
/// </summary>
/// <param name="applicationPath">The full path to the application executable.</param>
/// <param name="log">The log object.</param>
/// <returns>The application.</returns>
public static Application StartApplication(string applicationPath, Log log)
{
const string prefix = "Application - Start";
if (string.IsNullOrEmpty(applicationPath))
{
return null;
}
if (!File.Exists(applicationPath))
{
return null;
}
var processInfo = new ProcessStartInfo
{
FileName = applicationPath,
UseShellExecute = true,
WindowStyle = ProcessWindowStyle.Maximized,
};
log.Info(
prefix,
string.Format(
CultureInfo.InvariantCulture,
"Loading application from: {0}",
applicationPath));
var application = Application.Launch(processInfo);
log.Info(prefix, "Launched application, waiting for idle ...");
application.WaitWhileBusy();
log.Info(prefix, "Application launched and idle");
return application;
}
示例9: Info_Message_Null
public void Info_Message_Null()
{
LogManager.RegisterDebugListener();
var log = new Log(typeof (int));
log.Info((string) null);
}
示例10: VerifyCloseOnProjectOpenCheckbox
public TestResult VerifyCloseOnProjectOpenCheckbox(Application application, Log log)
{
const string prefix = "Close welcome tab on project open";
var result = new TestResult();
var assert = new Assert(result, log);
try
{
var startPage = TabProxies.GetStartPageTabItem(application, log);
if (startPage == null)
{
log.Info(prefix, "Opening start page.");
MenuProxies.SwitchToStartPageViaViewStartPageMenuItem(application, log);
}
startPage = TabProxies.GetStartPageTabItem(application, log);
if (startPage == null)
{
var message = "Failed to get the start page.";
log.Error(prefix, message);
result.AddError(prefix + " - " + message);
return result;
}
try
{
if (!startPage.IsSelected)
{
log.Info(prefix, "Setting focus to start page.");
startPage.Select();
}
}
catch (Exception e)
{
var message = string.Format(
CultureInfo.InvariantCulture,
"Failed to select the start page tab. Error was: {0}",
e);
log.Error(prefix, message);
result.AddError(prefix + " - " + message);
return result;
}
// Check 'keep open' flag
WelcomePageControlProxies.UncheckCloseWelcomePageOnProjectOpen(application, log);
// New button
var newProjectSearchCriteria = SearchCriteria
.ByAutomationId(WelcomeViewAutomationIds.NewProject);
var newProjectButton = (Button)startPage.Get(newProjectSearchCriteria);
if (newProjectButton == null)
{
var message = "Failed to get the 'New Project' button.";
log.Error(prefix, message);
result.AddError(prefix + " - " + message);
return result;
}
newProjectButton.Click();
// Check that the start page hasn't been closed
var currentStartPage = TabProxies.GetStartPageTabItem(application, log);
assert.IsNotNull(currentStartPage, prefix + " - Start page does not exist after opening project");
assert.IsFalse(currentStartPage.IsSelected, prefix + " - Start page is selected after opening project");
var currentProjectPage = TabProxies.GetProjectPageTabItem(application, log);
assert.IsNotNull(currentProjectPage, prefix + " - Project page does not exist after opening project");
assert.IsTrue(currentProjectPage.IsSelected, prefix + " - Project page is not selected after opening project");
// Check that File - close has been enabled
var fileCloseMenu = MenuProxies.GetFileCloseMenuItem(application, log);
assert.IsTrue(fileCloseMenu.Enabled, prefix + " - File - Close menu is not enabled");
// HACK: It seems that the File menu stays open when we check the File - close menu item
var fileMenu = MenuProxies.GetFileMenuItem(application, log);
if (fileMenu == null)
{
var message = "Failed to get the file menu.";
log.Error(prefix, message);
result.AddError(prefix + " - " + message);
return result;
}
if (fileMenu.IsFocussed)
{
fileMenu.Click();
}
// Close the project via the close button on the tab page
TabProxies.CloseProjectPageTab(application, log);
WelcomePageControlProxies.CheckCloseWelcomePageOnProjectOpen(application, log);
// New button
newProjectButton.Click();
// Check that the start page has been closed
currentStartPage = TabProxies.GetStartPageTabItem(application, log);
assert.IsNull(currentStartPage, prefix + " - Start page exists after opening project");
//.........這裏部分代碼省略.........
示例11: Info_ExceptionWithMessage_ExceptionNull
public void Info_ExceptionWithMessage_ExceptionNull()
{
LogManager.AddDebugListener();
var log = new Log(typeof (int));
ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => log.Info(null, string.Empty));
}
示例12: Info_ExceptionWithMessageFormat_MessageFormatNull
public void Info_ExceptionWithMessageFormat_MessageFormatNull()
{
LogManager.AddDebugListener();
var log = new Log(typeof (int));
var exception = new ArgumentNullException("log test");
log.Info(exception, null, 1);
}
示例13: CorrectlyLogsMessageWithBraces
public void CorrectlyLogsMessageWithBraces()
{
LogManager.AddDebugListener();
var log = new Log(typeof(int));
log.Info("This is a string with { and sometimes and ending }");
}
示例14: Info_MessageFormat
public void Info_MessageFormat()
{
LogManager.AddDebugListener();
var log = new Log(typeof (int));
LogMessageEventArgs eventArgs = null;
log.LogMessage += (sender, e) => eventArgs = e;
log.Info("log message {0}", 1);
Assert.IsNotNull(eventArgs);
Assert.AreEqual(log, eventArgs.Log);
Assert.AreEqual(LogEvent.Info, eventArgs.LogEvent);
Assert.AreEqual("log message 1", eventArgs.Message);
}
示例15: Info_ExceptionWithMessageFormat_MessageFormatNull
public void Info_ExceptionWithMessageFormat_MessageFormatNull()
{
LogManager.RegisterDebugListener();
var log = new Log(typeof(int));
var exception = new ArgumentNullException("log test");
ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => log.Info(exception, null, 1));
}