本文整理汇总了C#中ILogger.LogMessage方法的典型用法代码示例。如果您正苦于以下问题:C# ILogger.LogMessage方法的具体用法?C# ILogger.LogMessage怎么用?C# ILogger.LogMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILogger
的用法示例。
在下文中一共展示了ILogger.LogMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Check
public void Check(string url, ILogger logger)
{
using (var ping = new Ping())
{
PingReply pingReply = null;
try
{
pingReply = ping.Send(url);
}
catch (PingException ex)
{
logger.LogMessage(String.Format("Ping error: {0}", ex.Message));
return;
}
var result = String.Empty;
switch (pingReply.Status)
{
case IPStatus.Success:
result = "Available";
break;
case IPStatus.TimedOut:
result = "NotAvailable";
break;
default:
result = String.Format("Ping failed: {0}", pingReply.Status.ToString());
break;
}
logger.LogMessage(result);
}
}
示例2: Analyze
public DependencyAnalyzerResult Analyze(ILogger logger)
{
var result = new DependencyAnalyzerResult();
result.AnalyzedFiles = GetLibrariesAndExecutables().ToArray();
if (result.AnalyzedFiles.Length <= 0)
{
return result;
}
result.Assemblies = new Dictionary<string, AssemblyReferenceInfo>(StringComparer.OrdinalIgnoreCase);
foreach (var fileInfo in result.AnalyzedFiles.OrderBy(asm => asm.Name))
{
logger.LogMessage(string.Format("Checking file {0}", fileInfo.Name));
Assembly assembly;
try
{
if (!fileInfo.IsAssembly())
{
continue;
}
assembly = Assembly.ReflectionOnlyLoadFrom(fileInfo.FullName);
}
catch (Exception ex)
{
logger.LogWarning(string.Format("Failed to load assembly '{0}': {1}", fileInfo.FullName, ex.Message));
continue;
}
var assemblyReferenceInfo = GetAssemblyReferenceInfo(result.Assemblies, assembly.GetName());
assemblyReferenceInfo.ReflectionOnlyAssembly = assembly;
assemblyReferenceInfo.AssemblySource = AssemblySource.Local;
foreach (var referencedAssembly in assembly.GetReferencedAssemblies())
{
var referencedAssemblyReferenceInfo = GetAssemblyReferenceInfo(result.Assemblies, referencedAssembly); ;
assemblyReferenceInfo.AddReference(referencedAssemblyReferenceInfo);
referencedAssemblyReferenceInfo.AddReferencedBy(assemblyReferenceInfo);
}
}
foreach (var assembly in result.Assemblies.Values)
{
if (assembly.ReflectionOnlyAssembly != null)
{
continue;
}
logger.LogMessage(string.Format("Checking reference {0}", assembly.AssemblyName.Name));
try
{
assembly.ReflectionOnlyAssembly = Assembly.ReflectionOnlyLoad(assembly.AssemblyName.FullName);
assembly.AssemblySource = assembly.ReflectionOnlyAssembly.GlobalAssemblyCache ? AssemblySource.GAC : AssemblySource.Unknown;
}
catch (Exception ex)
{
// TODO: Show message?
}
}
return result;
}
示例3: PlaybackManager
/// <summary>
/// Creates new instance of <see cref="PlaybackManager"/>
/// </summary>
/// <param name="logger"><see cref="ILogger"/> instance</param>
/// <param name="applicationSettingsHelper"><see cref="IApplicationSettingsHelper"/> instance</param>
public PlaybackManager(ILogger logger, IApplicationSettingsHelper applicationSettingsHelper)
{
backgroundAudioInitializedEvent = new AutoResetEvent(false);
this.logger = logger;
this.applicationSettingsHelper = applicationSettingsHelper;
// Ensure that Background Audio is initialized by accessing BackgroundMediaPlayer.Current
var state = MediaPlayer.CurrentState;
logger.LogMessage($"Foreground playback manager: Current media player state is {state}.", LoggingLevel.Information);
BackgroundMediaPlayer.MessageReceivedFromBackground += onMessageReceivedFromBackground;
logger.LogMessage("Foreground playback manager initialized.", LoggingLevel.Information);
}
示例4: AudioManager
/// <summary>
/// Creates new instance of <see cref="AudioManager"/>
/// </summary>
/// <param name="logger">The logger instance</param>
/// <param name="applicationSettingsHelper">The application settings helper instance</param>
/// <param name="smtc">Instance of <see cref="SystemMediaTransportControls"/></param>
public AudioManager(
ILogger logger,
IApplicationSettingsHelper applicationSettingsHelper,
SystemMediaTransportControls smtc)
{
this.logger = logger;
this.applicationSettingsHelper = applicationSettingsHelper;
this.smtc = smtc;
logger.LogMessage("Initializing Background Audio Manager...");
setupSmtc();
subscribeToMediaEvents();
playlistLoading = new TaskCompletionSource<bool>();
playlistLoading.SetResult(true);
logger.LogMessage("BackgroundAudio: Background Audio Manager has been initialized.", LoggingLevel.Information);
}
示例5: Run
public async void Run(IBackgroundTaskInstance taskInstance)
{
deferral = taskInstance.GetDeferral();
Services.IoC.Register();
var container = Container.Instance;
logger = container.Resolve<ILogger>();
taskInstance.Task.Completed += onTaskCompleted;
taskInstance.Canceled += onTaskCanceled;
logger.LogMessage("BackgroundUpdater: Task initialized.", LoggingLevel.Information);
var episodeListManager = container.Resolve<IEpisodeListManager>();
await episodeListManager.Initialization;
var oldEpisodeList = EpisodeList.Instance.ToList();
await episodeListManager.LoadEpisodeListFromServerAsync();
var diff = EpisodeList.Instance.Except(oldEpisodeList).ToList();
if (diff.Any())
{
var downloadManager = container.Resolve<IDownloadManager>();
await downloadManager.Initialization;
foreach (var episode in diff)
{
await downloadManager.DownloadEpisode(episode);
}
}
deferral.Complete();
}
示例6: Kill
public void Kill(ILogger logger)
{
logger.LogMessage(string.Format("Killing device: {0}", FullName()));
TcpClient client = new TcpClient("localhost", Port);
using (var stream = client.GetStream())
{
byte[] results = new byte[100];
var readCount = stream.Read(results, 0, 100);
var resultText = Encoding.ASCII.GetString(results, 0, readCount);
logger.LogMessage("Connected to device console.");
logger.LogMessage(resultText);
logger.LogMessage("Sending kill command.");
var command = Encoding.ASCII.GetBytes("kill" + Environment.NewLine);
stream.Write(command, 0, command.Length);
stream.Flush();
readCount = stream.Read(results, 0, 100);
resultText = Encoding.ASCII.GetString(results, 0, readCount);
logger.LogMessage(resultText);
if (string.IsNullOrWhiteSpace(resultText) || !resultText.Contains("OK"))
{
throw new Exception(string.Format("Unable to kill emulator. Expected OK Response from kill command, but was: {0}", resultText));
}
logger.LogMessage("Emulated device killed.");
TimeSpan timeout = new TimeSpan(0, 0, 30);
stream.Close((int)timeout.TotalMilliseconds);
}
client.Close();
}
示例7: Check
public void Check(String url, ILogger logger)
{
var request = HttpWebRequest.Create(url);
try
{
using (var response = (HttpWebResponse)request.GetResponse())
{
if (response != null || response.StatusCode == HttpStatusCode.OK)
logger.LogMessage("Available");
else
logger.LogMessage("NotAvailable");
}
}
catch
{
logger.LogMessage("Web request error");
}
}
示例8: App
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
IoC.Register();
InitializeComponent();
UnhandledException -= onUnhandledException;
UnhandledException += onUnhandledException;
logger = container.Resolve<ILogger>();
logger.LogMessage("Application initialized.");
}
示例9: Loader
/// <summary>
/// Creates instance of <see cref="Loader"/>
/// </summary>
/// <param name="logger">The logger instance</param>
/// <param name="parser">The <see cref="IParser"/> instance</param>
public Loader(ILogger logger, IParser parser)
{
this.parser = parser;
this.logger = logger;
httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromSeconds(connectionTimeoutSeconds);
logger.LogMessage("Loader initialized.", LoggingLevel.Information);
}
示例10: Run
/// <summary>
/// The Run method is the entry point of a background task.
/// </summary>
/// <param name="taskInstance"></param>
public async void Run(IBackgroundTaskInstance taskInstance)
{
deferral = taskInstance.GetDeferral();
taskInstance.Canceled += OnCanceled;
taskInstance.Task.Completed += Taskcompleted;
IContainer container = Container.Instance;
Services.IoC.Register();
logger = container.Resolve<ILogger>();
logger.LogMessage($"BackgroundAudioTask {taskInstance.Task.Name} starting...");
try
{
// Ensure that Background Audio is initialized by accessing BackgroundMediaPlayer.Current
var state = BackgroundMediaPlayer.Current.CurrentState;
logger.LogMessage($"BackgroundAudioTask BackgroundMediaPlayer state is {state}.", LoggingLevel.Information);
applicationSettingsHelper = container.Resolve<IApplicationSettingsHelper>();
await applicationSettingsHelper.LoadPlaylist();
audioManager = new AudioManager(
logger,
applicationSettingsHelper,
SystemMediaTransportControls.GetForCurrentView());
BackgroundMediaPlayer.MessageReceivedFromForeground -= onMessageReceivedFromForeground;
BackgroundMediaPlayer.MessageReceivedFromForeground += onMessageReceivedFromForeground;
applicationSettingsHelper.SaveSettingsValue(Keys.IsBackgroundTaskRunning, true);
BackgroundMediaPlayer.SendMessageToForeground(new ValueSet { { Keys.IsBackgroundTaskRunning, null } });
logger.LogMessage($"BackgroundAudioTask initialized.", LoggingLevel.Information);
}
catch (Exception ex)
{
logger.LogMessage($"Unhandled exception in BackgroundAudioTask. {ex.Message}", LoggingLevel.Critical);
Dispose();
}
}
示例11: DownloadManager
/// <summary>
/// Creates new instance of <see cref="DownloadManager"/>
/// </summary>
/// <param name="logger">Instance of <see cref="ILogger"/></param>
/// <param name="playlist">Instance of <see cref="IPlayList"/></param>
/// <param name="loaderFactory">Instance of <see cref="ILoaderFactory"/></param>
/// <param name="parser">Instance of <see cref="IParser"/></param>
/// <param name="fileUtils">Instance of <see cref="IFileUtils"/></param>
public DownloadManager(
ILogger logger,
ILoaderFactory loaderFactory,
IParser parser,
IApplicationSettingsHelper applicationSettingsHelper,
IFileUtils fileUtils)
{
this.logger = logger;
this.loaderFactory = loaderFactory;
this.parser = parser;
this.applicationSettingsHelper = applicationSettingsHelper;
this.fileUtils = fileUtils;
Initialization = RetrieveActiveDownloads();
logger.LogMessage("DownloadManager: Initialized.", LoggingLevel.Information);
}
示例12: VoiceCommandsHandler
/// <summary>
/// Creates ne instance of <see cref="VoiceCommandsHandler"/>
/// </summary>
/// <param name="logger">Instance of <see cref="ILogger"/></param>
/// <param name="applicationSettingsHelper">Instance of <see cref="IApplicationSettingsHelper"/></param>
/// <param name="episodeListManager">Instance of <see cref="IEpisodeListManager"/></param>
/// <param name="playbackManager">Instance of <see cref="IPlaybackManager"/></param>
/// <param name="textSpeaker">Instance of <see cref="ITextSpeaker"/></param>
public VoiceCommandsHandler(
ILogger logger,
IApplicationSettingsHelper applicationSettingsHelper,
IEpisodeListManager episodeListManager,
IPlaybackManager playbackManager,
ITextSpeaker textSpeaker)
{
this.textSpeaker = textSpeaker;
this.playbackManager = playbackManager;
this.episodeListManager = episodeListManager;
this.applicationSettingsHelper = applicationSettingsHelper;
this.logger = logger;
Initialization = initializeAsync();
logger.LogMessage("Voice commands handler initialized.", LoggingLevel.Information);
}
示例13: MainPage
/// <summary>
/// Creates new instance of <see cref="MainPage"/>
/// </summary>
public MainPage()
{
// TODO: Think about using static properties
IContainer container = Container.Instance;
logger = container.Resolve<ILogger>();
applicationSettingsHelper = container.Resolve<IApplicationSettingsHelper>();
mainPageViewModel = container.Resolve<MainPageViewModel>();
NavigationCacheMode = NavigationCacheMode.Required;
InitializeComponent();
Loaded += onPageLoaded;
Unloaded += onPageUnloaded;
logger.LogMessage("MainPage has been created.");
}
示例14: Parser
/// <summary>
/// Creates new instance of <see cref="Parser"/>
/// </summary>
/// <param name="logger">The logger instance</param>
public Parser(ILogger logger)
{
this.logger = logger;
logger.LogMessage("Parser initialized.", LoggingLevel.Information);
}
示例15: MainPageViewModel
/// <summary>
/// Initializes new instance of <see cref="MainPageViewModel"/>
/// </summary>
/// <param name="playerModel">Instance of <see cref="PlayerViewModel"/></param>
/// <param name="episodesViewModel">Instance of <see cref="EpisodesViewModel"/></param>
/// <param name="logger"></param>
public MainPageViewModel(PlayerViewModel playerModel, EpisodesViewModel episodesViewModel, ILogger logger)
{
PlayerModel = playerModel;
EpisodesModel = episodesViewModel;
logger.LogMessage("Main page view model created.");
}