本文整理汇总了C#中ILogger.Warning方法的典型用法代码示例。如果您正苦于以下问题:C# ILogger.Warning方法的具体用法?C# ILogger.Warning怎么用?C# ILogger.Warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILogger
的用法示例。
在下文中一共展示了ILogger.Warning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDecimal
/// <summary>
/// Gets a decimal based on a static decimal as a string, or a pointer to a property of given event.
/// </summary>
/// <param name="logger">Logging instance for logging programs.</param>
/// <param name="value">The value to parse</param>
/// <param name="eventData">The event to fetch the value from should the "value" point to an event property.</param>
/// <returns></returns>
public static decimal? GetDecimal(ILogger logger, string value, LogEventData eventData)
{
decimal result;
if (!decimal.TryParse(value, NumberStyles.Float, CultureInfo.GetCultureInfo("en-us"), out result))
{
if (eventData.Properties.ContainsKey(value))
{
var p = eventData.Properties[value];
if (p is TimeSpan)
{
result = ((TimeSpan)p).Milliseconds;
}
else
{
try
{
result = Convert.ToDecimal(p);
}
catch (FormatException)
{
logger.Warning("Unable to send value to Ducksboard. Could not parse event property {EventPropertyKey} with value {Value} to decimal.", value, eventData.Properties[value]);
return null;
}
}
}
else
{
logger.Warning("Unable to send value to Ducksboard. Could not parse {Value}. Expected an decimal or an event property key.");
return null;
}
}
return result;
}
示例2: SafeSetSuccess
public static void SafeSetSuccess(TaskCompletionSource promise, ILogger logger)
{
if (promise != TaskCompletionSource.Void && !promise.TryComplete())
{
logger.Warning("Failed to complete task successfully because it is done already: {0}", promise);
}
}
示例3: SafeSetFailure
public static void SafeSetFailure(TaskCompletionSource promise, Exception cause, ILogger logger)
{
if (promise != TaskCompletionSource.Void && !promise.TrySetException(cause))
{
logger.Warning(
"Failed to set exception on task successfully because it is done already: {0}; Cause: {1}", promise,
cause);
}
}
示例4: LogException
public static void LogException(ILogger log, Exception ex, ErrorDataContract error, HttpStatusCode code)
{
if (ex == null)
return;
log.Warning(@"[Exception][Type:{0}][Err:{1}][HTTPStatus:{2}][Message:{3}][CorrId:{4}]
*********************** DevMessage ***********************
{5}
**********************************************************
Exception:
{6}",
ex.GetType().Name, error.FaultCode, code, error.Message, error.CorrelationId, error.DeveloperMessage, ex);
}
示例5: FindBestTextureSize
/// <summary>
/// Utility function to check that the texture size is supported on the graphics platform for the provided graphics profile.
/// </summary>
/// <param name="textureFormat">The desired type of format for the output texture</param>
/// <param name="platform">The graphics platform</param>
/// <param name="graphicsProfile">The graphics profile</param>
/// <param name="textureSizeInput">The texture size input.</param>
/// <param name="textureSizeRequested">The texture size requested.</param>
/// <param name="generateMipmaps">Indicate if mipmaps should be generated for the output texture</param>
/// <param name="logger">The logger.</param>
/// <returns>true if the texture size is supported</returns>
/// <exception cref="System.ArgumentOutOfRangeException">graphicsProfile</exception>
public static Size2 FindBestTextureSize(TextureFormat textureFormat, GraphicsPlatform platform, GraphicsProfile graphicsProfile, Size2 textureSizeInput, Size2 textureSizeRequested, bool generateMipmaps, ILogger logger)
{
var textureSize = textureSizeRequested;
// compressed DDS files has to have a size multiple of 4.
if (platform == GraphicsPlatform.Direct3D11 && textureFormat == TextureFormat.Compressed
&& ((textureSizeRequested.Width % 4) != 0 || (textureSizeRequested.Height % 4) != 0))
{
textureSize.Width = unchecked((int)(((uint)(textureSizeRequested.Width + 3)) & ~(uint)3));
textureSize.Height = unchecked((int)(((uint)(textureSizeRequested.Height + 3)) & ~(uint)3));
}
var maxTextureSize = 0;
// determine if the desired size if valid depending on the graphics profile
switch (graphicsProfile)
{
case GraphicsProfile.Level_9_1:
case GraphicsProfile.Level_9_2:
case GraphicsProfile.Level_9_3:
if (generateMipmaps && (!IsPowerOfTwo(textureSize.Width) || !IsPowerOfTwo(textureSize.Height)))
{
// TODO: TEMPORARY SETUP A MAX TEXTURE OF 1024. THIS SHOULD BE SPECIFIED DONE IN THE ASSET INSTEAD
textureSize.Width = Math.Min(MathUtil.NextPowerOfTwo(textureSize.Width), 1024);
textureSize.Height = Math.Min(MathUtil.NextPowerOfTwo(textureSize.Height), 1024);
logger.Warning("Graphic profiles 9.1/9.2/9.3 do not support mipmaps with textures that are not power of 2. Asset is automatically resized to " + textureSize);
}
maxTextureSize = graphicsProfile >= GraphicsProfile.Level_9_3 ? 4096 : 2048;
break;
case GraphicsProfile.Level_10_0:
case GraphicsProfile.Level_10_1:
maxTextureSize = 8192;
break;
case GraphicsProfile.Level_11_0:
case GraphicsProfile.Level_11_1:
case GraphicsProfile.Level_11_2:
maxTextureSize = 16384;
break;
default:
throw new ArgumentOutOfRangeException("graphicsProfile");
}
if (textureSize.Width > maxTextureSize || textureSize.Height > maxTextureSize)
{
logger.Error("Graphic profile {0} do not support texture with resolution {2} x {3} because it is larger than {1}. " +
"Please reduce texture size or upgrade your graphic profile.", graphicsProfile, maxTextureSize, textureSize.Width, textureSize.Height);
return new Size2(Math.Min(textureSize.Width, maxTextureSize), Math.Min(textureSize.Height, maxTextureSize));
}
return textureSize;
}
示例6: DisposeExceptionSafe
public static void DisposeExceptionSafe(this IDisposable disposable, ILogger logger)
{
if (disposable == null) return;
if (logger == null) throw new ArgumentNullException(nameof(logger));
try
{
disposable.Dispose();
}
catch (Exception e)
{
logger.Warning(e, $"Failed to dispose '{disposable.GetType().Name}'");
}
}
示例7: RestartHandler
private static async Task<bool> RestartHandler(Exception ex, int retryCount, ILogger logger, IComponentIdentity component)
{
try
{
bool doDelay = retryCount % 5 == 0;
if (doDelay)
{
await
logger.Warning(
$"Error occurred in component {component.FullyQualifiedName}. Restarting in 30 seconds.", ex);
await Task.Delay(TimeSpan.FromSeconds(30));
}
else
{
await logger.Warning($"Error occurred in component {component.FullyQualifiedName}. Restarting immediately.", ex);
}
}
catch (Exception)
{
// swallow any issues
}
return true;
}
示例8: Main
private static void Main(string[] args)
{
_logger = new ConsoleLogger();
if (args.Length != 3)
{
_logger.Warning("Format is: TestApplication.exe username password sitecollectionurl");
return;
}
string username = args[0];
string password = args[1];
string webUrl = args[2];
SecureString securePassword = GetSecureStringFromString(password);
using (var clientContext = new ClientContext(webUrl))
{
clientContext.Credentials = new SharePointOnlineCredentials(username, securePassword);
var migrator = new Migrator(clientContext, _logger);
migrator.Migrate(Assembly.GetAssembly(typeof(ShowTitle)));
}
}
示例9: LoadTemporaryAssets
/// <summary>
/// Refreshes this package from the disk by loading or reloading all assets.
/// </summary>
/// <param name="log">The log.</param>
/// <param name="cancelToken">The cancel token.</param>
/// <returns>A logger that contains error messages while refreshing.</returns>
/// <exception cref="System.InvalidOperationException">Package RootDirectory is null
/// or
/// Package RootDirectory [{0}] does not exist.ToFormat(RootDirectory)</exception>
public void LoadTemporaryAssets(ILogger log, CancellationToken? cancelToken = null)
{
if (log == null) throw new ArgumentNullException("log");
// If FullPath is null, then we can't load assets from disk, just return
if (FullPath == null)
{
log.Warning("Fullpath not set on this package");
return;
}
// Clears the assets already loaded and reload them
TemporaryAssets.Clear();
// List all package files on disk
var listFiles = ListAssetFiles(log, this, cancelToken);
var progressMessage = String.Format("Loading Assets from Package [{0}]", FullPath.GetFileNameWithExtension());
// Display this message at least once if the logger does not log progress (And it shouldn't in this case)
var loggerResult = log as LoggerResult;
if (loggerResult == null || !loggerResult.IsLoggingProgressAsInfo)
{
log.Info(progressMessage);
}
// Update step counter for log progress
for (int i = 0; i < listFiles.Count; i++)
{
var fileUPath = listFiles[i].Item1;
var sourceFolder = listFiles[i].Item2;
if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
{
log.Warning("Skipping loading assets. PackageSession.Load cancelled");
break;
}
// Update the loading progress
if (loggerResult != null)
{
loggerResult.Progress(progressMessage, i, listFiles.Count);
}
// Try to load only if asset is not already in the package or assetRef.Asset is null
var assetPath = fileUPath.MakeRelative(sourceFolder).GetDirectoryAndFileName();
try
{
// An exception can occur here, so we make sure that loading a single asset is not going to break
// the loop
var assetFullPath = fileUPath.FullPath;
var asset = LoadAsset(log, assetFullPath, assetPath, fileUPath);
// Create asset item
var assetItem = new AssetItem(assetPath, asset)
{
IsDirty = false,
Package = this,
SourceFolder = sourceFolder.MakeRelative(RootDirectory)
};
// Set the modified time to the time loaded from disk
assetItem.ModifiedTime = File.GetLastWriteTime(assetFullPath);
FixAssetImport(assetItem);
// Add to temporary assets
TemporaryAssets.Add(assetItem);
}
catch (Exception ex)
{
int row = 1;
int column = 1;
var yamlException = ex as YamlException;
if (yamlException != null)
{
row = yamlException.Start.Line + 1;
column = yamlException.Start.Column;
}
var module = log.Module;
var assetReference = new AssetReference<Asset>(Guid.Empty, fileUPath.FullPath);
// TODO: Change this instead of patching LoggerResult.Module, use a proper log message
if (loggerResult != null)
{
loggerResult.Module = "{0}({1},{2})".ToFormat(Path.GetFullPath(fileUPath.FullPath), row, column);
}
log.Error(this, assetReference, AssetMessageCode.AssetLoadingFailed, ex, fileUPath, ex.Message);
if (loggerResult != null)
//.........这里部分代码省略.........
示例10: LoadTemplates
/// <summary>
/// Loads the templates.
/// </summary>
/// <param name="log">The log result.</param>
private void LoadTemplates(ILogger log)
{
foreach (var templateDir in TemplateFolders)
{
foreach (var filePath in templateDir.Files)
{
try
{
var file = new FileInfo(filePath);
if (!file.Exists)
{
log.Warning("Template [{0}] does not exist ", file);
continue;
}
var templateDescription = AssetSerializer.Load<TemplateDescription>(file.FullName);
templateDescription.FullPath = file.FullName;
Templates.Add(templateDescription);
}
catch (Exception ex)
{
log.Error("Error while loading template from [{0}]", ex, filePath);
}
}
}
}
示例11: SendMessages
//----------------------------------------------------------------------------
private List<string> SendMessages(ILogger testLogger)
{
// We send two blocks of messages, validating so the internal rolling file.
Random r = new Random();
string currentMsg = null;
List<string> initialList = new List<string>();
//----------
currentMsg = "Message A-" + r.Next().ToString();
initialList.Add(currentMsg);
testLogger.Warning(currentMsg);
currentMsg = "Message B-" + r.Next().ToString();
initialList.Add(currentMsg);
testLogger.Warning(currentMsg);
//----------
// Waiting to give time to send...
System.Threading.Thread.Sleep(10000);
//----------
currentMsg = "Message C-" + r.Next().ToString();
initialList.Add(currentMsg);
testLogger.Warning(currentMsg);
currentMsg = "Message D-" + r.Next().ToString();
initialList.Add(currentMsg);
testLogger.Warning(currentMsg);
//----------
// Waiting to give time to send...
System.Threading.Thread.Sleep(10000);
//----------
return initialList;
}
开发者ID:XML-Travelgate,项目名称:serilog-sinks-googlecloudpubsub,代码行数:43,代码来源:GoogleCloudPubSubSinkTests.cs
示例12: LoadTemporaryAssets
/// <summary>
/// Refreshes this package from the disk by loading or reloading all assets.
/// </summary>
/// <param name="log">The log.</param>
/// <param name="assetFiles">The asset files (loaded from <see cref="ListAssetFiles"/> if null).</param>
/// <param name="cancelToken">The cancel token.</param>
/// <param name="filterFunc">A function that will filter assets loading</param>
/// <returns>A logger that contains error messages while refreshing.</returns>
/// <exception cref="System.InvalidOperationException">Package RootDirectory is null
/// or
/// Package RootDirectory [{0}] does not exist.ToFormat(RootDirectory)</exception>
public void LoadTemporaryAssets(ILogger log, IList<PackageLoadingAssetFile> assetFiles = null, CancellationToken? cancelToken = null, Func<PackageLoadingAssetFile, bool> filterFunc = null)
{
if (log == null) throw new ArgumentNullException(nameof(log));
// If FullPath is null, then we can't load assets from disk, just return
if (FullPath == null)
{
log.Warning("Fullpath not set on this package");
return;
}
// Clears the assets already loaded and reload them
TemporaryAssets.Clear();
// List all package files on disk
if (assetFiles == null)
assetFiles = ListAssetFiles(log, this, cancelToken);
var progressMessage = $"Loading Assets from Package [{FullPath.GetFileNameWithExtension()}]";
// Display this message at least once if the logger does not log progress (And it shouldn't in this case)
var loggerResult = log as LoggerResult;
if (loggerResult == null || !loggerResult.IsLoggingProgressAsInfo)
{
log.Info(progressMessage);
}
var context = new AssetMigrationContext(this, log);
// Update step counter for log progress
var tasks = new List<System.Threading.Tasks.Task>();
for (int i = 0; i < assetFiles.Count; i++)
{
var assetFile = assetFiles[i];
if (filterFunc != null && !filterFunc(assetFile))
{
continue;
}
// Update the loading progress
loggerResult?.Progress(progressMessage, i, assetFiles.Count);
var task = cancelToken.HasValue ?
System.Threading.Tasks.Task.Factory.StartNew(() => LoadAsset(context, assetFile, loggerResult), cancelToken.Value) :
System.Threading.Tasks.Task.Factory.StartNew(() => LoadAsset(context, assetFile, loggerResult));
tasks.Add(task);
}
if (cancelToken.HasValue)
{
System.Threading.Tasks.Task.WaitAll(tasks.ToArray(), cancelToken.Value);
}
else
{
System.Threading.Tasks.Task.WaitAll(tasks.ToArray());
}
// DEBUG
// StaticLog.Info("[{0}] Assets files loaded in {1}", assetFiles.Count, clock.ElapsedMilliseconds);
if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
{
log.Warning("Skipping loading assets. PackageSession.Load cancelled");
}
}
示例13: LogAll
private void LogAll(ILogger logger)
{
logger.Error("Error Logged");
logger.Warning("Warning Logged");
logger.Information("Information Logged");
logger.Debug("Debug Logged");
}
示例14: ProcessRootAssetReferences
/// <summary>
/// Fix and/or remove invalid RootAssets entries.
/// Note: at some point, we might want to make IContentReference be part of the same workflow as standard asset references.
/// </summary>
/// <param name="rootAssets">The root assets to check.</param>
/// <param name="referencedPackage">The package where to look for root reference.</param>
/// <param name="log">The logger.</param>
private void ProcessRootAssetReferences(RootAssetCollection rootAssets, Package referencedPackage, ILogger log)
{
foreach (var rootAsset in rootAssets.ToArray())
{
// Update Asset references (AssetReference, AssetBase, ContentReference)
var id = rootAsset.Id;
var newItemReference = referencedPackage.Assets.Find(id);
// If asset was not found by id try to find by its location
if (newItemReference == null)
{
newItemReference = referencedPackage.Assets.Find(rootAsset.Location);
if (newItemReference != null)
{
// If asset was found by its location, just emit a warning
log.Warning(package, rootAsset, AssetMessageCode.AssetReferenceChanged, rootAsset, newItemReference.Id);
}
}
// If asset was not found, remove the reference
if (newItemReference == null)
{
log.Warning(package, rootAsset, AssetMessageCode.AssetNotFound, rootAsset);
rootAssets.Remove(rootAsset.Id);
package.IsDirty = true;
continue;
}
// Only update location that are actually different
var newLocationWithoutExtension = newItemReference.Location;
if (newLocationWithoutExtension != rootAsset.Location || newItemReference.Id != rootAsset.Id)
{
rootAssets.Remove(rootAsset.Id);
rootAssets.Add(new AssetReference<Asset>(newItemReference.Id, newLocationWithoutExtension));
package.IsDirty = true;
}
}
}
示例15: LoadTemporaryAssets
/// <summary>
/// Refreshes this package from the disk by loading or reloading all assets.
/// </summary>
/// <param name="log">The log.</param>
/// <param name="assetFiles">The asset files (loaded from <see cref="ListAssetFiles"/> if null).</param>
/// <param name="cancelToken">The cancel token.</param>
/// <returns>A logger that contains error messages while refreshing.</returns>
/// <exception cref="System.InvalidOperationException">Package RootDirectory is null
/// or
/// Package RootDirectory [{0}] does not exist.ToFormat(RootDirectory)</exception>
public void LoadTemporaryAssets(ILogger log, IList<PackageLoadingAssetFile> assetFiles = null, CancellationToken? cancelToken = null)
{
if (log == null) throw new ArgumentNullException("log");
// If FullPath is null, then we can't load assets from disk, just return
if (FullPath == null)
{
log.Warning("Fullpath not set on this package");
return;
}
// Clears the assets already loaded and reload them
TemporaryAssets.Clear();
// List all package files on disk
if (assetFiles == null)
assetFiles = ListAssetFiles(log, this, cancelToken);
var progressMessage = String.Format("Loading Assets from Package [{0}]", FullPath.GetFileNameWithExtension());
// Display this message at least once if the logger does not log progress (And it shouldn't in this case)
var loggerResult = log as LoggerResult;
if (loggerResult == null || !loggerResult.IsLoggingProgressAsInfo)
{
log.Info(progressMessage);
}
// Update step counter for log progress
for (int i = 0; i < assetFiles.Count; i++)
{
var fileUPath = assetFiles[i].FilePath;
var sourceFolder = assetFiles[i].SourceFolder;
if (cancelToken.HasValue && cancelToken.Value.IsCancellationRequested)
{
log.Warning("Skipping loading assets. PackageSession.Load cancelled");
break;
}
// Update the loading progress
if (loggerResult != null)
{
loggerResult.Progress(progressMessage, i, assetFiles.Count);
}
// Check if asset has been deleted by an upgrader
if (assetFiles[i].Deleted)
{
IsDirty = true;
filesToDelete.Add(assetFiles[i].FilePath);
continue;
}
// An exception can occur here, so we make sure that loading a single asset is not going to break
// the loop
try
{
AssetMigration.MigrateAssetIfNeeded(log, assetFiles[i]);
// Try to load only if asset is not already in the package or assetRef.Asset is null
var assetPath = fileUPath.MakeRelative(sourceFolder).GetDirectoryAndFileName();
var assetFullPath = fileUPath.FullPath;
var assetContent = assetFiles[i].AssetContent;
var asset = LoadAsset(log, assetFullPath, assetPath, fileUPath, assetContent);
// Create asset item
var assetItem = new AssetItem(assetPath, asset)
{
IsDirty = assetContent != null,
Package = this,
SourceFolder = sourceFolder.MakeRelative(RootDirectory)
};
// Set the modified time to the time loaded from disk
if (!assetItem.IsDirty)
assetItem.ModifiedTime = File.GetLastWriteTime(assetFullPath);
// TODO: Let's review that when we rework import process
// Not fixing asset import anymore, as it was only meant for upgrade
// However, it started to make asset dirty, for ex. when we create a new texture, choose a file and reload the scene later
// since there was no importer id and base.
//FixAssetImport(assetItem);
// Add to temporary assets
TemporaryAssets.Add(assetItem);
}
catch (Exception ex)
{
int row = 1;
int column = 1;
//.........这里部分代码省略.........