本文整理汇总了C#中System.Logger.Error方法的典型用法代码示例。如果您正苦于以下问题:C# Logger.Error方法的具体用法?C# Logger.Error怎么用?C# Logger.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Logger
的用法示例。
在下文中一共展示了Logger.Error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestEventViewer
public void TestEventViewer()
{
var l = new Logger("bUtilitySource");
l.Error("test logger 1");
l.Error(new Exception("an exception sample"));
}
示例2: _LoadFromFile
private ErrorSuccess<IVsixPackage, string> _LoadFromFile(string file, Logger log, ErrorSuccessFactory<IVsixPackage, string> ef)
{
log.Info($"Reading {file}");
ZipArchive zipFile;
try
{
zipFile = ZipFile.OpenRead(file);
}
catch (Exception ex)
{
log.Error($"{file} is not a zip archive.", ex);
return ef.Error($"{file} is not a zip archive: {ex.Message}");
}
using (zipFile)
{
var manifestEntry = zipFile.Entries.FirstOrDefault(entry => entry.FullName == Entry.Manifest);
if (manifestEntry == null)
{
return ef.Error($"{file} does not contain a {Entry.Manifest} entry.");
}
return _CreateFromZipManifest(file, manifestEntry, log, ef);
}
}
示例3: BuildArray
/// <summary>
/// Build an Array of a particular type from a list of tokens.
/// The Type must be one that can be built with Convert.ChangeType.
/// There are various ways to specify how many elements to parse.
/// WARNING: This will throw an exception if any tokens cannot be
/// converted.
/// </summary>
/// <param name="tokens">The ArrayList of tokens.</param>
/// <param name="i">The starting (and ending) index. This is
/// modified, and left pointing at the last used token.</param>
/// <param name="type">The Type of the array elements.</param>
/// <param name="endToken">An optional end Token to look for.
/// Parsing stops when a token equal to this is found.
/// If this is null, then it is not used.</param>
/// <param name="maxLength">The maximum number of array elements
/// to parse. If this is negative, then it is not used.</param>
/// <param name="log">A Logger to use for messages.</param>
/// <returns>The Array, or null for error.</returns>
public static Array BuildArray(ArrayList tokens, ref int i, Type type,
Token endToken, int maxLength, Logger log)
{
int len = tokens.Count;
if (i >= len)
{
log.Error("BuildArray: Input index too large.");
return(null);
}
// put the objects into an array list first, since we don't
// know length
ArrayList list = new ArrayList();
// allow null endToken specified
if (endToken == null) endToken = new EofToken();
Token token = null;
token = (Token)tokens[i++];
int arrayLength = 0;
while ((!(token is EofToken)) && (token != endToken) && (i < len)
&& ((maxLength < 0) || (arrayLength < maxLength)))
{
Object o = token.ConvertToType(type);
list.Add(o);
arrayLength++;
token = (Token)tokens[i++];
}
i--; // went one past
return(list.ToArray(type));
}
示例4: Main
static void Main(string[] args)
{
ILayout simpleLayout = new SimpleLayout();
IAppender consoleAppender = new ConsoleAppender(simpleLayout);
ILogger logger = new Logger(consoleAppender);
logger.Error("Error parsing JSON");
logger.Info(string.Format("User {0} successfully registered.", "Pesho"));
Console.WriteLine(new string('-', 20));
//We create a second Appender and add it to the existing ILogger object
IFileAppender fileAppender = new FileAppender(simpleLayout);
fileAppender.File = "log.txt";
logger.AddAppender(fileAppender);
logger.Fatal("mscorlib.dll does not respond");
logger.Critical("No connection string found in App.config");
Console.WriteLine(new string('-', 20));
//We set the new XML Layout on each Appender that the Logger object uses
foreach (IAppender appender in logger.Appenders)
{
appender.Layout = new XmlLayout();
}
logger.Fatal("mscorlib.dll does not respond");
logger.Critical("No connection string found in App.config");
Console.WriteLine(new string('-', 20));
//We set the Report Level Minimum at Error
foreach (IAppender appender in logger.Appenders)
{
appender.ReportLevelMinimum = Enums.ReportLevel.Error;
}
logger.Info("Everything seems fine");
logger.Warning("Warning: ping is too high - disconnect imminent");
logger.Error("Error parsing request");
logger.Critical("No connection string found in App.config");
logger.Fatal("mscorlib.dll does not respond");
Console.WriteLine(new string('-', 20));
}
示例5: ExampleOne
private static void ExampleOne()
{
ILayout simpleLayout = new SimpleLayout();
IAppender consoleAppender =
new ConsoleAppender(simpleLayout);
ILogger logger = new Logger(consoleAppender);
logger.Error("Error parsing JSON.");
logger.Info(string.Format("User {0} successfully registered.", "Pesho"));
}
示例6: LoggerGenerateOutputTest
public void LoggerGenerateOutputTest()
{
Logger logger = new Logger(System.Reflection.Assembly.GetExecutingAssembly());
logger.Exception("exception #1");
logger.Exception("exception #2");
logger.Exception("exception #3");
logger.Exception("exception #4");
logger.Error("Error 1");
logger.Error("Error 2");
logger.Error("Error 3");
logger.Warn("Warn 1");
logger.Warn("Warn 2");
logger.Warn("Warn 3");
string id = logger.LogResume();
Assert.Pass(id);
}
示例7: ExampleTwo
private static void ExampleTwo()
{
var simpleLayout = new SimpleLayout();
var consoleAppender = new ConsoleAppender(simpleLayout);
var fileAppender = new FileAppender(simpleLayout);
fileAppender.File = "log.txt";
var logger = new Logger(consoleAppender, fileAppender);
logger.Error("Error parsing JSON.");
logger.Info(string.Format("User {0} successfully registered.", "Pesho"));
logger.Warn("Warning - missing files.");
}
示例8: LoadFromFile
public ErrorSuccess<IVsixPackage, string> LoadFromFile(string file, Logger log)
{
var ef = new ErrorSuccessFactory<IVsixPackage, string>();
try
{
return _LoadFromFile(file, log, ef);
}
catch (Exception ex)
{
log.Error($"An unexpected error occurred while trying to read {file} as a vsix.", ex);
return ef.Error($"An unexpected error occurred while trying to read {file} as a vsix: {ex.Message}");
}
}
示例9: ExampleFour
private static void ExampleFour()
{
var simpleLayout = new SimpleLayout();
var consoleAppender = new ConsoleAppender(simpleLayout);
consoleAppender.ReportLevel = ReportLevel.Error;
var logger = new Logger(consoleAppender);
logger.Info("Everything seems fine");
logger.Warn("Warning: ping is too high - disconnect imminent");
logger.Error("Error parsing request");
logger.Critical("No connection string found in App.config");
logger.Fatal("mscorlib.dll does not respond");
}
示例10: CSharpProject
public CSharpProject(ISolution solution,
Logger logger,
string folderPath,
IFileSystem fileSystem)
: base(fileSystem, logger)
{
_fileSystem = fileSystem;
_logger = logger;
_solution = solution;
Files = new List<CSharpFile>();
References = new List<IAssemblyReference>();
DirectoryInfoBase folder;
try
{
folder = _fileSystem.DirectoryInfo.FromDirectoryName(folderPath);
}
catch (DirectoryNotFoundException)
{
logger.Error("Directory not found - " + folderPath);
return;
}
var files = folder.GetFiles("*.cs", SearchOption.AllDirectories);
foreach (var file in files)
{
_logger.Debug("Loading " + file.FullName);
Files.Add(new CSharpFile(this, file.FullName));
}
this.ProjectContent = new CSharpProjectContent()
.SetAssemblyName(AssemblyName)
.AddAssemblyReferences(References)
.AddOrUpdateFiles(Files.Select(f => f.ParsedFile));
AddMsCorlib();
AddReference(LoadAssembly(FindAssembly("System.Core")));
var dlls = folder.GetFiles("*.dll", SearchOption.AllDirectories);
foreach (var dll in dlls)
{
_logger.Debug("Loading assembly " + dll.FullName);
AddReference(dll.FullName);
}
}
示例11: Error
public void Error()
{
// arrange
var logger = new Logger();
var logs = new StringBuilder();
logger.SetWriter(new StringWriter(logs));
logger.AddCategory("error");
// act
logger.Debug("debug message");
logger.Info("info message");
logger.Error("error message");
// assert
Assert.Equal("error message", logs.ToString().Trim());
}
示例12: CurrentDomain_UnhandledException
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
Logger logger = new Logger();
Exception ex = (Exception)e.ExceptionObject;
logger.Error("Unhandled exception occured in application. " + ex.Message, ex);
Console.WriteLine("MyHandler caught : " + ex.Message);
Console.WriteLine("Runtime terminating: {0}", e.IsTerminating);
ErrorModal form = new ErrorModal(ex.Message);
form.ShowDialog();
}
catch (Exception)
{
}
}
示例13: Temperature_DS1822
/// <summary>
/// Costruttore senza ID del sensore, trovato automaticamente dal software
/// Prende il primo termometro che trova
/// </summary>
/// <param name="Name"></param>
/// <param name="Simulation"></param>
/// <param name="Logger"></param>
public Temperature_DS1822(string Name, bool Simulation, Logger Logger)
: base(Name, Simulation, Logger)
{
Logger.Debug("Temperature_DS1822_Constructor senza ID. SensorId automatico");
if (!Simulation)
{
// creazione del termometro; se il parametro DeviceIndex = 0 usa il primo sensore che trova
try
{
termometro = new Ds18b20Connection(0);
}
catch (Exception ex)
{
Logger.Error("Temperature_DS1822_Constructor senza ID. " + ex.Message);
return;
}
}
Initialization();
}
示例14: TestLogging
public void TestLogging()
{
var config = new FileConfiguration
{
CreateDateFolder = true,
DaysToKeep = 3,
Path = AppDomain.CurrentDomain.BaseDirectory
};
var target = new FileTarget("Everything", config);
target.Enqueue(new LogEntry
{
CreatedAt = DateTime.Now,
LogLevel = LogLevel.Debug,
Message = "Hello world",
LoggedType = GetType(),
MethodName = MethodBase.GetCurrentMethod().Name,
ThreadId = Thread.CurrentThread.ManagedThreadId,
UserName = Thread.CurrentPrincipal.Identity.Name
?? Environment.UserName
});
var target2 = new PaddedFileTarget("EVeryone", config);
target2.Enqueue(new LogEntry
{
CreatedAt = DateTime.Now,
LogLevel = LogLevel.Debug,
Message = "Hello world",
LoggedType = GetType(),
MethodName = MethodBase.GetCurrentMethod().Name,
ThreadId = Thread.CurrentThread.ManagedThreadId,
UserName = Thread.CurrentPrincipal.Identity.Name
?? Environment.UserName
});
var logger = new Logger(GetType(), new[] {target2, target});
logger.Info("Hello");
logger.Debug("Hello");
logger.Warning("Hello");
logger.Error("Hello");
}
示例15: TestLogging
public void TestLogging()
{
var config = new FileConfiguration
{
CreateDateFolder = true,
DaysToKeep = 3,
Path = @"d:\logfiles"
};
var target = new FileTarget("Everything", config);
target.Enqueue(new LogEntry
{
CreatedAt = DateTime.Now,
LogLevel = LogLevel.Debug,
Message = "Hello world",
StackFrames = new StackTrace().GetFrames(),
ThreadId = Thread.CurrentThread.ManagedThreadId,
UserName = Thread.CurrentPrincipal.Identity.Name
?? Environment.UserName
});
var target2 = new PaddedFileTarget("EVeryone", config);
target2.Enqueue(new LogEntry
{
CreatedAt = DateTime.Now,
LogLevel = LogLevel.Debug,
Message = "Hello world",
StackFrames = new StackTrace().GetFrames(),
ThreadId = Thread.CurrentThread.ManagedThreadId,
UserName = Thread.CurrentPrincipal.Identity.Name
?? Environment.UserName
});
var logger = new Logger(GetType(), new[] {target2, target});
logger.Info("Hello");
logger.Debug("Hello");
logger.Warning("Hello");
logger.Error("Hello");
}