Click here to Skip to main content
15,895,799 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: .Net Logging Pin
Jeremy Falcon26-Jan-17 8:45
professionalJeremy Falcon26-Jan-17 8:45 
GeneralRe: .Net Logging Pin
PIEBALDconsult27-Jan-17 2:46
mvePIEBALDconsult27-Jan-17 2:46 
GeneralRe: .Net Logging Pin
Jeremy Falcon27-Jan-17 5:52
professionalJeremy Falcon27-Jan-17 5:52 
GeneralRe: .Net Logging Pin
EbenRoux30-Jan-17 0:59
EbenRoux30-Jan-17 0:59 
GeneralRe: .Net Logging Pin
PIEBALDconsult30-Jan-17 2:45
mvePIEBALDconsult30-Jan-17 2:45 
GeneralRe: .Net Logging Pin
Ian Shlasko26-Jan-17 7:46
Ian Shlasko26-Jan-17 7:46 
GeneralRe: .Net Logging Pin
dandy7226-Jan-17 7:51
dandy7226-Jan-17 7:51 
GeneralRe: .Net Logging Pin
OriginalGriff26-Jan-17 8:06
mveOriginalGriff26-Jan-17 8:06 
Kevin Marois wrote:
at the most basicl level, what's wrong with this:
 
public class Logger
{
    public static string LogFile { get; set; }
 
    static Logger()
    {
        if (string.IsNullOrEmpty(LogFile))
        {
            var path = System.Reflection.Assembly.GetEntryAssembly().Location;
            LogFile = string.Format("{0}\MyLogFile.txt", path);
        }
    }

Well, it won't work in production for starters!
The Executing assembly in production is normally in a folder that "hangs off" "Program Files" or "Program Files (x86)", and folders in that path are normally write protected for antivirus reasons.
Use a "publically writable" folder like one below Application.CommonAppDataPath or Environment.SpecialFolder.CommonApplicationData :
C#
/// <summary>
/// Get the Application Guid
/// </summary>
public static Guid AppGuid
    {
    get
        {
        Assembly asm = Assembly.GetEntryAssembly();
        object[] attr = (asm.GetCustomAttributes(typeof(GuidAttribute), true));
        return new Guid((attr[0] as GuidAttribute).Value);
        }
    }
/// <summary>
/// Get the current assembly Guid.
/// <remarks>
/// Note that the Assembly Guid is not necessarily the same as the
/// Application Guid - if this code is in a DLL, the Assembly Guid
/// will be the Guid for the DLL, not the active EXE file.
/// </remarks>
/// </summary>
public static Guid AssemblyGuid
    {
    get
        {
        Assembly asm = Assembly.GetExecutingAssembly();
        object[] attr = (asm.GetCustomAttributes(typeof(GuidAttribute), true));
        return new Guid((attr[0] as GuidAttribute).Value);
        }
    }
/// <summary>
/// Get all users data folder
/// </summary>
public static string AllUsersDataFolder
    {
    get
        {
        Guid appGuid = AppGuid;
        string folderBase = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
        string dir = string.Format(@"{0}\{1}\", folderBase, appGuid.ToString("B").ToUpper());
        return CheckDir(dir);
        }
    }

Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

GeneralRe: .Net Logging Pin
Kevin Marois26-Jan-17 8:07
professionalKevin Marois26-Jan-17 8:07 
GeneralRe: .Net Logging Pin
Howard Hoffman27-Jan-17 2:39
Howard Hoffman27-Jan-17 2:39 
GeneralRe: .Net Logging Pin
lopatir26-Jan-17 8:12
lopatir26-Jan-17 8:12 
GeneralRe: .Net Logging Pin
Gerry Schmitz26-Jan-17 8:15
mveGerry Schmitz26-Jan-17 8:15 
GeneralRe: .Net Logging Pin
Richard Deeming26-Jan-17 8:20
mveRichard Deeming26-Jan-17 8:20 
JokeRe: .Net Logging Pin
Slacker00726-Jan-17 8:41
professionalSlacker00726-Jan-17 8:41 
GeneralRe: .Net Logging Pin
Nish Nishant26-Jan-17 8:51
sitebuilderNish Nishant26-Jan-17 8:51 
GeneralRe: .Net Logging Pin
Slacker00726-Jan-17 11:19
professionalSlacker00726-Jan-17 11:19 
GeneralRe: .Net Logging Pin
Sander Rossel26-Jan-17 9:49
professionalSander Rossel26-Jan-17 9:49 
GeneralRe: .Net Logging Pin
Mladen Janković26-Jan-17 11:54
Mladen Janković26-Jan-17 11:54 
GeneralRe: .Net Logging Pin
Sander Rossel26-Jan-17 21:36
professionalSander Rossel26-Jan-17 21:36 
GeneralRe: .Net Logging Pin
Rob Philpott26-Jan-17 10:28
Rob Philpott26-Jan-17 10:28 
GeneralRe: .Net Logging Pin
TheGreatAndPowerfulOz26-Jan-17 12:12
TheGreatAndPowerfulOz26-Jan-17 12:12 
GeneralRe: .Net Logging Pin
Uwe Laas26-Jan-17 19:49
Uwe Laas26-Jan-17 19:49 
GeneralRe: .Net Logging Pin
Mehdi Gholam26-Jan-17 20:11
Mehdi Gholam26-Jan-17 20:11 
GeneralRe: .Net Logging Pin
Didjeeh26-Jan-17 20:14
Didjeeh26-Jan-17 20:14 
GeneralRe: .Net Logging Pin
SonnyHarbour26-Jan-17 21:22
SonnyHarbour26-Jan-17 21:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.