-
-
Notifications
You must be signed in to change notification settings - Fork 9
Simplify.Log
Alexanderius edited this page Jan 23, 2021
·
3 revisions
Provides ILogger
interface and Logger
class for file-based log.
With Logger
you can write messages to a text log, including just some strings or exception data with full stack trace, line numbers and inner exceptions stack traces.
Available at NuGet as binary package
Simple string log message example:
[01.03.2014 18:24:11:330] Main : Hello world!!!
Exception log message example:
[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.Default
ambient context provides default logger.
- By default, if no Logger configuration exist in config file, data will be written to
Logs.log
file in current directory (calling assembly location), or web-site root for APS.NET web-sites and WCF services, If a log file size will exceed a limit of 5 mb, then it will be cleaned.
Writing a simple string to a log:
Logger.Default.Write("Hello world!!!");
Writing an exception to a log:
try
{
...
}
catch (Exception e)
{
Logger.Default.Write(e);
}
App.config configuration example:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<section name="Logger" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
<!-- Override log file name and use relative path by default -->
<Logger>
<add key="FileName" value="MyLog.log"/>
</Logger>
</configuration>
Logger
can be instantiated with specified settings section in config file.
Fo example, from MyLoggerSettings section in config file:
var logger = new Logger("MyLoggerSettings");
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<section name="MyLoggerSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
<!-- Override log file name and use relative path by default -->
<MyLoggerSettings>
<add key="FileName" value="MyLog.log"/>
</MyLoggerSettings>
</configuration>
<Logger>
<!-- Override log file name and use full path type -->
<add key="FileName" value="C:\Logs\MyApp.log"/>
<add key="PathType" value="FullPath"/>
<!-- Maximum file size in KB -->
<add key="MaxFileSize" value="5000"/>
<!-- Sends a copy of a data written to the log file in to trace (visual Studio output window) -->
<add key="ShowTraceOutput" value="true"/>
</Logger>