Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand correctly, you want to create one log file per thread per process per machine. So, given the description of what you are doing, your log file names might look something like this:</p> <pre><code>machine1_processid1_thread1.log machine1_processid1_thread2.log machine1_processid2_thread1.log machine2_processid1_thread1.log etc... </code></pre> <p>Do you care what the actual values are for any of the components of the log file name? In other words, is it really important that the log file name be made up of identifiable components (machine name, thread id, process id, etc)? Or is it sufficient that the log file names simply be unique?</p> <p>One approach would be to simply use a Guid. So, where you are creating your log file name, you could do something like this:</p> <pre><code>string logFileName = Guid.NewGuid().ToString() + ".log" </code></pre> <p>That would probably achieve your goal of having uniquely named log files. I suppose that it is possible that there could eventually be a collision of Guids, but I don't know enough about that to say for sure. But, this approach is not really very user friendly. Who really wants to look a folder full of guid-based filenames and try to determine which one they really want to look at?</p> <p>Maybe it is useful to know the machine and the process that is generating the logs? That way, if you knew or suspected that some problem was coming from a specific machine or a specific process, you could find just those files that were generated from that machine/process. In that case, you could still use a Guid to name the file, but you could augment with machine name and/or process:</p> <pre><code>string logFileName = string.Format("{0}_{1}_{2}.log", Environment.MachineName, Process.GetCurrentProcess().ProcessName, Guid.NewGuid()); </code></pre> <p>This should give a log file name that is a bit more user friendly, and is still unique across all of your criteria.</p> <p>In summary, I would recommend trying to use a Guid since the stated purpose of it is to provide a Globally Unique Identifier, rather than trying to come up with your own algorithm. The main drawback, as I noted above, is that it could be annoying to dig through a folder full of guid-based log files, trying to find the "right" one. Augmenting the filename with more user friendly data such as machine name, process name, etc could help.</p> <p>Finally, I will mention that if you do use a Guid, there are several options available for formatting the guid.</p> <p><a href="http://msdn.microsoft.com/en-us/library/97af8hh4.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/97af8hh4.aspx</a></p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. COThanks wageoghe. I don't really care about the name of the log since there is a log cleanup function to append these log files together into a regular log file automatically. The thing is where do I get this GUID. My understanding for a website (I could be wrong.) is sometimes although it seems I am still on the same thing. The backend may already changed to another one. And if the previous one is still holding the lock, the new one won't be able to write the log.
      singulars
    2. COTo be honest, I primarily do desktop development, so I am not well versed in some of the intricacies of web development. I figured that if you were already generating the file name as you described, that you could just change how you generate the name to include the use of Guid.NewGuid. If you are configuring log4net through code, which it sounds like you are since I don't think the log4net configuration allows you to create a file name as you describe (with the hash code of the Thread, for example), then I would guess that you could just create the log file name (and guid) when you ...
      singulars
    3. CO... configure log4net. I am not familiar enough with web development to give much more information on when/how multiple processes/threads come into to play and how best to use log4net in that environment. I suspect that if you dig around here on SO you will find some good information about using log4net with asp.net that might help you out.
      singulars
 

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