I created an ILogger
interface and a ListViewLogger
class that implements ILogger
, now ILogger
has a method (SetListViewReference
) that shouldn't be there since not all Loggers will log to a ListView, and i don't know where to place it, because i'm doing dependency injection i need that method though, so what should i do ? thanks!
using System;
using System.Windows.Forms;
namespace AutoTweet
{
public interface ILogger
{
void Log(string text);
void SetListViewReference(ListView listview);
}
public class ListViewLogger : ILogger
{
private ListView _lvLog;
public void Log(string text)
{
_lvLog?.Items.Add(makeLvi(text));
}
public void SetListViewReference(ListView listview)
{
_lvLog = listview;
}
private ListViewItem makeLvi(string text)
{
ListViewItem ret = new ListViewItem { Text = DateTime.Now.ToString() };
ret.SubItems.Add(text);
return ret;
}
}
}