I am new using lamda expressions and i am trying to figure some things.
I have created the following part of code which code returns the file path of a log file.
public static string GetLogFile()
{
var fileTarget = LogManager.Configuration.AllTargets.Where(t=>t.Name == "LogName") as FileTarget;
return fileTarget == null ? string.Empty : fileTarget.FileName.Render(new LogEventInfo { Level = LogLevel.Info });
}
My problem is that fileTarget is empty when i am using:
LogManager.Configuration.AllTargets.Where(t=>t.Name == "LogName")
But if i change that line of code as
LogManager.Configuration.AllTargets.FirstOrDefault(t=>t.Name == "LogName")
Returns the correct path for my log file. Can anyone explain to me if there is a major difference between Where and FirstOrDefault?