Note that there are some explanatory texts on larger screens.

plurals
  1. POShould I use log4net directly in my domain model objects?
    primarykey
    data
    text
    <p>I'm wondering if it's bad practice to use log4net directly on my domain object... I'll be using ELMAH for my exceptions on the ASP.NET MVC application side, but for some informational purposes I'd like to log some data about the domain model itself.</p> <p>Given the following domain object:</p> <pre><code> public class Buyer { private int _ID; public int ID { get { return _ID; } set { _ID = value; } } private IList&lt;SupportTicket&gt; _SupportTickets=new List&lt;SupportTicket&gt;(); public IList&lt;SupportTicket&gt; SupportTickets { get { return _SupportTickets.ToList&lt;SupportTicket&gt;().AsReadOnly(); } } public void AddSupportTicket(SupportTicket ticket) { if (!SupportTickets.Contains(ticket)) { _SupportTickets.Add(ticket); } } } </code></pre> <p>Is adding logging behavior in the AddSupportTicketMethod a bad idea...so essentialy it'd look like this:</p> <pre><code> public class Buyer { protected static readonly ILog log = LogManager.GetLogger(typeof(SupportTicket)); public Buyer() { log4net.Config.XmlConfigurator.Configure(); } private int _ID; public int ID { get { return _ID; } set { _ID = value; } } private IList&lt;SupportTicket&gt; _SupportTickets=new List&lt;SupportTicket&gt;(); public IList&lt;SupportTicket&gt; SupportTickets { get { return _SupportTickets.ToList&lt;SupportTicket&gt;().AsReadOnly(); } } public void AddSupportTicket(SupportTicket ticket) { if (!SupportTickets.Contains(ticket)) { _SupportTickets.Add(ticket); } else { log.Warn("Duplicate Ticket Not Added."); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload