-
-
Notifications
You must be signed in to change notification settings - Fork 10
Simplify.Log
Provides ILogger interface and Logger class for file-based logging.
With Logger, you can write messages to a text log, including simple strings or exception data with full stack trace, line numbers, and inner exceptions stack traces.
Available at NuGet as binary package
[01.03.2014 18:24:11:330] Main : Hello world!!!
[26.02.2014 13:39:00:023] NHibernate.Exceptions.GenericADOException : could not execute query
[ select flightexcl0_.ID as ID5462_, flightexcl0_.FlightNumber as FlightNu2_5462_ from FlightsExcludeList flightexcl0_ ]
[SQL: select flightexcl0_.ID as ID5462_, flightexcl0_.FlightNumber as FlightNu2_5462_ from FlightsExcludeList flightexcl0_]
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
at NHibernate.Hql.Ast.ANTLR.Loader.QueryLoader.List(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.List(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Engine.Query.HQLQueryPlan.PerformList(QueryParameters queryParameters, ISessionImplementor session, IList results)
at NHibernate.Impl.SessionImpl.List(IQueryExpression queryExpression, QueryParameters queryParameters, IList results)
at NHibernate.Impl.AbstractSessionImpl.List(IQueryExpression queryExpression, QueryParameters parameters)
at NHibernate.Impl.ExpressionQueryImpl.List()
at NHibernate.Linq.DefaultQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery)
at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)
at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression)
at Remotion.Linq.QueryableBase`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at FluentNHibernate.Extender.DbConnection.GetList[T](Expression`1 filterFunc)
at Processing.Processing.Processor..ctor(IDbConnection dbConnection, IList`1 officesForProcessing) in c:\CCNet\WorkingDirectory\Processing\src\Processing\Processing\Processor.cs:line 81
at Processing.Service.OnWork(Object state) in c:\CCNet\WorkingDirectory\SsrProcessing\src\SsrProcessing\Service.cs:line 52
[Inner Exception] Oracle.ManagedDataAccess.Client.OracleException : Connection request timed out
at OracleInternal.ConnectionPool.PoolManager`3.CreateNewPR(Int32 reqCount, Boolean bForPoolPopulation, ConnectionString csWithDiffOrNewPwd, String instanceName)
at OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword)
at Oracle.ManagedDataAccess.Client.OracleConnection.Open()
at NHibernate.Connection.DriverConnectionProvider.GetConnection()
at NHibernate.AdoNet.ConnectionManager.GetConnection()
at NHibernate.AdoNet.AbstractBatcher.Prepare(IDbCommand cmd)
at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies)
at NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters)
Logger (implementing ILogger, namespace Simplify.Log) is instantiated directly, optionally with configuration.
- When created with default parameters, data is written to a
Logs.logfile using a relative path (calling assembly location). If a log file size exceeds the limit (5000 KB ≈ 5 MB by default), it will be cleaned.
using Simplify.Log;
ILogger logger = new Logger();logger.Write("Hello world!!!");try
{
...
}
catch (Exception e)
{
logger.Write(e);
}WriteWeb(Exception e) writes the same data but returns it formatted with HTML line breaks (<br />). The Generate / GenerateWeb methods build the same formatted message text without writing it to the file.
The parameterized constructor lets you override the defaults directly:
// public Logger(int maxFileSize = 5000, string fileName = "Logs.log",
// LoggerPathType pathType = LoggerPathType.Relative, bool showTraceOutput = false)
var logger = new Logger(
maxFileSize: 5000,
fileName: @"C:\Logs\MyApp.log",
pathType: LoggerPathType.FullPath,
showTraceOutput: true);LoggerPathType is an enum with two values: Relative (default, relative to the calling assembly location) and FullPath (the file name is treated as an absolute path).
Logger can be created from an IConfiguration. By default it reads the Logger section; a different section name can be passed as the second argument:
using Microsoft.Extensions.Configuration;
using Simplify.Log;
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
// Reads the "Logger" section by default
var logger = new Logger(config);
// Or specify a custom section name
var customLogger = new Logger(config, "MyLoggerSettings");{
"Logger": {
// Override log file name and use full path type
"FileName": "C:\\Logs\\MyApp.log",
"PathType": "FullPath",
// Maximum file size in KB
"MaxFileSize": "5000",
// Sends a copy of data written to the log file to trace (Visual Studio output window)
"ShowTraceOutput": "true"
}
}All configuration keys (FileName, MaxFileSize, PathType, ShowTraceOutput) are optional; omitted keys fall back to the defaults above.