How can you specify the file name for a Log4net SmtpPickupDirAppender? - log4net

By default the SmtpPickupDirAppender appender creates a file without an extension. I can't find that there is a parameter (or other option) to configure the file extension.
The email service that picks up the file from the directory specified in the "pickupDir" parameter requires a file extension.
Is there a way to specify one?

Not built in.
From the source, it looks like it just creates a file name based on a guid and doesn't offer any configuration options,
filePath = Path.Combine(m_pickupDir, SystemInfo.NewGuid().ToString("N"));
writer = File.CreateText(filePath);
However, if you pull the source, it should be relatively straight forward to create your own appender that adds an file extension.

Related

Always create types in new file

How can I instruct ReSharper to always create a new type in a new file instead of within the file I'm working on? I want to do this using the alt+enter+enter command.

simple puppet script to copy files

Hi I'm new to puppet and trying to work on a sample to copy files from one location to another location. Any sample script to do that?
Ex: I've my file at d:\temp\test.txt and I want to copy this file to E:\mycopy\ folder.
You can "ensure" that the file at target location exists and provide the file to be copied as source in file type. A partial code snippet only showing relevant parts:
file { 'E:\mycopy\folder\filename':
ensure => present,
source => "d:\temp\test.txt",
}
Check the documentation of file type here and how source attribute behaves here. Now this will work with a few caveats :
If you are using absolute file path as source - then the file should be present on agent machine
If you are serving file from Puppet's file server then the source file should be in appropriate location in puppet's file server.
But what is your exact purpose? Similar thing can be achieved with content attribute of file type or other attributes

using FileChooser to save a file with default filename

I wat to save a file.I use this.
FileChooser fileChooser = new FileChooser();
File file = fileChooser.showSaveDialog(null);
But in the dialog I want to suggest a name for the file, so that the user only selects a directory for the given file.The name of the file is known already.So i want to suggest that filename.
ThankYou.
This is now fixed in Javafx 2.2.45 (bundled with java 7.0_45 now) and you can do what the OP is suggesing with the following property of fileChooser, setInitialFilename, used as such:
FileChooser myFile = new FileChooser();
myFile.setInitialFileName("Whatever_file_I_want.coolFile");
Now, I don't think there is anyway to STOP the user from choosing a different file, but at leas this will give them a default you want them to pick.
Initial file name providing - it is a thing, which requires to transfer your string (initial name) through native call, to the call of the native file chooser. It is a complex thing, and you can look at these issues about its implementing :
http://javafx-jira.kenai.com/browse/RT-16111 (main one)
http://javafx-jira.kenai.com/browse/RT-24588
http://javafx-jira.kenai.com/browse/RT-24612
They all have fix version lombard, so, they are fixed in JDK 8.
So, you can specify initial file name for a file, starting from JDK 8 (you can access it, downloading JDK early access).
Recently, I've tested this feature, and it is working.
There is a method setInitialName() or smth like that.
And, as I've mentioned, it is a complex thing, and you are not likely to be able to implement it by yourself (until you are able to build jfx).
So, the decision - to wait until JDK8 release, or to use early access builds. Or, to use your own implementation of file chooser.
Here's a workaround that worked for me:
you can use javafx.stage.DirectoryChooser to select a directory for the file you want to save and after saving create a new file in this directory with the default name and extension.
DirectoryChooser dc = new DirectoryChooser();
File file = dc.showDialog(null);
if (file != null) {
file = new File(file.getAbsolutePath() + "/dafaultFilename.extension");}

Proper way to differentiate pst and dbx files in bash shell

I want to identify the file-format of the input file given to my shell script - whether a .pst or a .dbx file. I checked How to check the extension of a filename in a bash script?. That one deals with txt files and two methods are given there -
check if the extension is txt
check if the mime type is application/text etc.
I tried file -ib <filename> on a .pst and a .dbx file and it showed application/octet-stream for both. However, if I just do file <filename>, then I get
this for the dbx file -
file1.dbx: Microsoft Outlook Express DBX File Message database
and this for the pst file -
file2.pst: Microsoft Outlook binary email folder (Outlook >=2003)
So, my questions are -
is it better to use mime type detection everytime when the output can be anything and we need a proper check?
How to apply mime type check in this case - both returning "application/octet-stream"?
Update
I didn't want to do an extension based detection because it seems we just can't be sure on a Unix system, that a .dbx file truly is a dbx file. Since file <filename> returns a line which contains the correct information of the file (e.g. "Microsoft Outlook Express DBX File Message database"). That means the file command is able to identify the file type properly. Then why does it not get the correct information in file -ib <filename> command?
Will parsing the string output of file <filename> be fine? Is it advisable assuming I only need to identify a narrow set of data storage files of outlook family (MS Outlook Express, MS Office Outlook 2003,2007,2010 etc.). A small text identifier like application/dbx which could be compared would be all I need.
The file command relies on having a file type detection database which includes rules for the file types that you expect to encounter. It may not be possible to recognize these file types if the file content doesn't have a unique code near the beginning of the file.
Note that the -i option to emit mime types actually uses a separate "magic" numbers file to recognize file types rather than translating long descriptions to file types. It is quite possible for these two databases to be out of sync. If your application really needs to recognize these two file types I suggest that you look at the Linux source code for "file" to see how they recognize them and then code this recognition algorithm right into your app.
If you want to do the equivalent of DOS file type detection, then strip the extension off the filename (everything after the last period) and look up that string in your own table where you define the types that you need.

log4 net Dynamic file name assigning

I want to know how to dynamically assign file name using Log4net .My application is such that 10 different files should be dynamically created based on user input ,and later based on the name the corresponding file name needs to be picked up and information written to it
For example in my application based on my buisness requirement for every xml file a corresponding log file with the same name as xml file should be created .Later whenever I do any modification to the xml file an entry needs to be in the corresponding log file
Please help . I having trouble to get control of the appropriate log to write it
Have not done this, but there are probably a number of ways of doing this, so this may not be the best way, but it should work
public OpenLogFile(string fileName)
{
log4net.Layout.ILayout layout = new log4net.Layout.PatternLayout("%d [%t]%-5p : - %m%n");;
log4net.Appender.FileAppender appender = new log4net.Appender.FileAppender(layout , filename);
appender.Threshold = log4net.Core.Level.Info;
log4net.Config.BasicConfigurator.Configure(appender);
}
Then just call OpenLogfile when you need to switch files.
You might need to tweak the layout or appender type.
A big disadvantage of this method is you losing the xml configuration and the ability to change settings at runtime. So a better way might be to configure your appender in the xml file to use a property
eg
file type="log4net.Util.PatternString" value="Logfiles\Log_For_%property{MyLogFileName}"
Then in your code you could change the property
log4net.GlobalContext.Properties["MyLogFileName"] = ...;
The tricky bit is to get log4net to reload itself. I haven't read the documentation of this, so I don't know if there is a way of forcing a reload. It might work if you just call log4net.Config.XmlConfigurator.ConfigureAndWatch again. Otherwise it should work if you opened the xml file and saved it again (without needing to change anything)
Hope this helps.

Resources