制作者的介绍仅有上面的一句话。 更多详情请阅读仓库 README。 仓库 README ↗
正在加载完整 README。
查看完整 README ↗“Anything you want, you got it.
Anything you need, you got it.
Anything at all, you got it, baby…”
Logging service library for .NET.
By default, Roy will save the exceptions and logs in the “exceptions” and "logs" folders. These folders will be created inside the bin folder. This behavior can be changed by using the LogExtension.Settings object.
Roy can also save the exceptions and logs on the computer event system (Windows/Linux), send the exceptions and logs by E-mail, save exceptions and logs into multiple databases, and/or submit them to multiple APIs. These behaviors can be set by using the LogExtension.Settings object. Check the Settings Wiki for more information.
The following code demonstrates the basic usage of Roy exception logging. Just add Roy.Logging to your using statements. You can now run the "SaveAsync" method to save the exception. There is no need for any further configuration or object injection.
using Roy.Logging;
public void AmazingCode()
{
try
{
// Evil code fails.
}
catch (Exception ex)
{
ex.SaveAsync();
}
}
The following code demonstrates the basic usage of Roy logging. Just add Roy.Logging to your using statements. You can now run the "LogAsync" method to log any object or primitive. There is no need for any further configuration or object injection.
using Roy.Logging;
public void AmazingCode()
{
Artist singer = new Artist();
singer.Name = "Roy";
singer.LastName = "Orbinson";
singer.Description = "Roy Kelton Orbison was an American singer, songwriter, and musician.";
singer.LogAsync();
"Anything you want, you got it".LogAsync(); //You can log primitives too.
}
To log every unhandled exception on your MVC app, call UseRoyExceptionHandler in Program.cs after your own error handling (UseExceptionHandler, UseDeveloperExceptionPage) and before the app.Run() method call. Roy logs the exception and throws it again, so your own error page still runs. Called before your own handler, Roy would never see the exception: the handler nearer the page catches it first.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
}
// Add the line below after your own error handling, before the app.Run() method call.
app.UseRoyExceptionHandler();
...
app.Run();
You can load the Roy Logging settings from the appsettings.json file by passing the builder object to the UseRoyExceptionHandler method.
var builder = WebApplication.CreateBuilder(args);
...
// Pass the builder object to the UseRoyExceptionHandler method.
app.UseRoyExceptionHandler(builder);
...
app.Run();
{
"AllowedHosts": "*",
"RoyLogging": {
"Exception": {
"DefaultFolderName": "exceptionsUT",
"SaveLogOnFile": true,
"LoadInformationSettings": {
"LogApplicationInformation": true,
"LogMachineInformation": true,
"LogMethodInformation": true
},
"Emails": [
{
"UserAccount": "[email protected]",
"UserPassword": "wK2jPUxzqdnsDBNCUj",
"From": "[email protected]",
"DisplayNameFrom": "ROY Logger",
"Server": {
"Host": "smtp.ethereal.email"
},
"Receivers": [
{
"To": "[email protected]",
"BCC": "",
"CC": "",
"Subject": ""
}
],
"Language": "English"
}
],
"APIs": [
{
"URL": "https://api.restful-api.dev/objects",
"LevelsToPost": [
"Critical"
]
}
],
"Databases": [
{
"DatabaseName": "RoyDev",
"StringConnection": "Data Source=DBName;Initial Catalog=RoyDev;Integrated Security=false;Trusted_Connection=True;TrustServerCertificate=True;User ID=madona;Password=45Pasword3",
"TableName": ""
}
]
},
"Log": {
"DefaultFolderName": "logsUT",
"LoadInformationSettings": {
"LogApplicationInformation": true,
"LogMachineInformation": true,
"LogMethodInformation": true
},
"Emails": [
{
"UserAccount": "[email protected]",
"UserPassword": "wK2jPUxzqdnsDBNCUj",
"From": "[email protected]",
"DisplayNameFrom": "ROY Logger",
"Server": {
"Host": "smtp.ethereal.email"
},
"Receivers": [
{
"To": "[email protected]",
"BCC": "",
"CC": "",
"Subject": ""
}
],
"Language": "English",
"LevelsToReport": [ "Warning" ]
}
],
"APIs": [
{
"URL": "https://api.restful-api.dev/objects"
}
],
"Databases": [
{
"DatabaseName": "RoyDev",
"StringConnection": "Data Source=DBName;Initial Catalog=RoyDev;Integrated Security=false;Trusted_Connection=True;TrustServerCertificate=True;User ID=madona;Password=45Pasword3",
"TableName": ""
}
]
}
}
}
Download the latest release, then add a reference to Avalon.Base.Extensions.dll and Roy.Logging.dll libraries. If you are developing an MVC application, you will also need to add a reference to Roy.Logging.MVC.dll. To build from source, clone the repository and build source/Roy.Logging/Roy.Logging.sln with the .NET 10 SDK. The Avalon.Base.Extensions.dll it needs is in source/Libraries/Avalon/Base, so nothing else is required.
By default, the exceptions and logs will be saved in the bin folder. For instance, "bin\Debug\net7.0". Inside this folder, Roy will create an “exceptions” and a "logs" folder. This behavior can be changed by modifying the object LogExtension.Settings static property.
You can make any changes to the settings by calling the LogExtension.Settings static property.
I will write more documentation as soon as I have some spare time.
For more information visit Roy's wiki.