その中で最も確実な方法をカスタムイベントログやイベントソースのインストール中にa.ネットサービス

StackOverflow https://stackoverflow.com/questions/115488

質問

私が困難な時に確実に創出に取り付けたり取り外したりするイベントソースのインストール中にmy.Net Windowsサービスです。

こちらのコードからProjectInstallerクラス:

// Create Process Installer
ServiceProcessInstaller spi = new ServiceProcessInstaller();
spi.Account = ServiceAccount.LocalSystem;

// Create Service
ServiceInstaller si = new ServiceInstaller();
si.ServiceName = Facade.GetServiceName();
si.Description = "Processes ...";
si.DisplayName = "Auto Checkout";
si.StartType = ServiceStartMode.Automatic;

// Remove Event Source if already there
if (EventLog.SourceExists("AutoCheckout"))
    EventLog.DeleteEventSource("AutoCheckout");

// Create Event Source and Event Log     
EventLogInstaller log = new EventLogInstaller();
log.Source = "AutoCheckout";
log.Log = "AutoCheckoutLog";

Installers.AddRange(new Installer[] { spi, si, log });

のファサードの方法を参照だけを返す文字列名をログするサービスなど

このコード作品のほとんどの時間ですが、最近はインストール後に思ったのが始ログのエントリの撮影中に体調不良を訴用ログの代わりにカスタムログに出力する。以下のエラーのログとしても

の説明のためのイベントID(0)ソース(AutoCheckoutできません。ローカルコンピュータはないが、必要なレジストリ情報やメッセージのDLLファイルの表示メッセージからのリモートコンピュータ.ることができる利用/AUXSOURCE=フラグを取得するこ説明;ヘルプを参照ください、支援します。

何らかの理由でいずれかを適切に除去、ソース中のアンインストールで作成中にそれをインストールします。

のお役に立てるようベストプラクティスのこちらよろしくお願いいたします。

よろしく!

また、ここではサンプルの皆様にお伝えしたくて書き込み例外をログに:

// Write to Log
EventLog.WriteEntry(Facade.GetEventLogSource(), errorDetails, EventLogEntryType.Error, 99);

に関するstephbuの回答: のおすすめのパスがインストールスクリプトおよびinstallutil、Windowsの設定を日常的に見られる。

を使用していセットアッププロジェクト実行のインストールサービスを設定すoff.............るかどうかを利用したいinstallutil.exe または、windowsの設定をプロジェクトになっていると思うの両方の電話と同じProjectInstallerクラスを示します。

私の状態でのテスト機が原因のエラーの場合はログにない真に削除されるまでの再起動.私の実験りだという課題を解決する.

編集: に興味がある私にとっては、必ず火を登録ソースのログの名前のインストール中に、サービスです。ここでは、サービスしていたものを設置し、ソースを削除し、再利用、ソース中のその後の施設

いかたについて学習する機会WiXしてみる。

役に立ちましたか?

解決

一番のお勧めする使用しないで設定はプロジェクトできます。で非常に厳しい限界がある。私は非常に良好な結果と WiX

他のヒント

ServiceInstaller クラスを自動的に作成し EventLogInstaller とを知っていただくことで内部に、独自のインストーラーです。

みのあるコード:

ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
serviceProcessInstaller.Password = null;
serviceProcessInstaller.Username = null;
serviceProcessInstaller.Account = ServiceAccount.LocalSystem;

// serviceInstaller
ServiceInstaller serviceInstaller = new ServiceInstaller();
serviceInstaller.ServiceName = "MyService";
serviceInstaller.DisplayName = "My Service";
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.Description = "My Service Description";
// kill the default event log installer
serviceInstaller.Installers.Clear(); 

// Create Event Source and Event Log     
EventLogInstaller logInstaller = new EventLogInstaller();
logInstaller.Source = "MyService"; // use same as ServiceName
logInstaller.Log = "MyLog";

// Add all installers
this.Installers.AddRange(new Installer[] {
   serviceProcessInstaller, serviceInstaller, logInstaller
});

カップルのものはこちら

作成イベントログと源の愛の延ます。これは主に、権を行うために必要なされているアクションをかたを聞応用とその力があります。

また、削除した場合は、イベントログやソースの入 めぐり 削除の場合、サーバを再起動できま悪態を削除してしまった場合、再現できな跳ねる。もっ暗黙のルール名の紛争によるメタデータに格納されている。

のおすすめのパスがインストールスクリプトおよびinstallutil、Windowsの設定を日常的に見られる。

してくださいstephbuの"もの国"のイベントログが、思い入れます。また、一部の困難があります。

しかし、最良の方法にしたんだイベントでログインの実際とTraceListener.を設定することができて本サービスのアプリです。config:

http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlogtracelistener.aspx

セクションがあり近くの中のページを使用する方法を記述していEventLog物件を指定しEventLogをご希望の書きます。

い役立っています。

私も続いている helbの 提案を除き、その使用は基本的に標準のデザイナーの発生の授業(デフォルトのオブジェ"ServiceProcessInstaller1"と"ServiceInstaller1").そこで少し簡単なバージョンでも私はVBで、人は時にVBすることができない。

として tartheode れるべきではありません修正のデザイナー-発生ProjectInstallerクラス ProjectInstaller.デザイナー。vb ファイルがす ができ 具体的な方法を以下に示する ProjectInstaller.vb ファイルです。作成後に通常のProjectInstallerを使用してい標準を追加でインストーラーズ)のみを変更したのNew()にProjectInstallerクラスです。後は通常の"InitializeComponent()"呼挿入します:

  ' remove the default event log installer 
  Me.ServiceInstaller1.Installers.Clear()

  ' Create an EventLogInstaller, and set the Event Source and Event Log      
  Dim logInstaller As New EventLogInstaller
  logInstaller.Source = "MyServiceName"
  logInstaller.Log = "MyCustomEventLogName"

  ' Add the event log installer
  Me.ServiceInstaller1.Installers.Add(logInstaller)

これに合わせて、インストーラを起動した ない のイベントソースのログで作成された新しいカスタムログファイルです。

しかし、螺周辺に十分なったビットの混乱にサーバーです。この問題のカスタムログした場合には、イベントソース名の存在に関連する 間違った ログファイル(例えば、に"アプリのログの代わりに新しいカスタムログ)のソース名にする必要があ削除その後の機械を再起動;その後ソースを作成できます。協会の正しいログにあります。Microsoftの助けを明確にし、 EventLogInstallerクラスの説明):

このインストールメソッドが例外をスローし る場合は物件に一致す ソース名で登録されているため、 さまざまなイベントでログインしています。

そのため、私もこの機能は私のサービスは、要求されたときに呼び出されるサービス開始

   Private Function EventLogSourceNameExists() As Boolean
      'ensures that the EventSource name exists, and that it is associated to the correct Log 

      Dim EventLog_SourceName As String = Utility.RetrieveAppSetting("EventLog_SourceName")
      Dim EventLog_LogName As String = Utility.RetrieveAppSetting("EventLog_LogName")

      Dim SourceExists As Boolean = EventLog.SourceExists(EventLog_SourceName)
      If Not SourceExists Then
         ' Create the source, if it does not already exist.
         ' An event log source should not be created and immediately used.
         ' There is a latency time to enable the source, it should be created
         ' prior to executing the application that uses the source.
         'So pass back a False to cause the service to terminate.  User will have 
         'to re-start the application to make it work.  This ought to happen only once on the 
         'machine on which the service is newly installed

         EventLog.CreateEventSource(EventLog_SourceName, EventLog_LogName)  'create as a source for the SMRT event log
      Else
         'make sure the source is associated with the log file that we want
         Dim el As New EventLog
         el.Source = EventLog_SourceName
         If el.Log <> EventLog_LogName Then
            el.WriteEntry(String.Format("About to delete this source '{0}' from this log '{1}'.  You may have to kill the service using Task Manageer.  Then please reboot the computer; then restart the service two times more to ensure that this event source is created in the log {2}.", _
            EventLog_SourceName, el.Log, EventLog_LogName))

            EventLog.DeleteEventSource(EventLog_SourceName)
            SourceExists = False  'force a close of service
         End If
      End If
      Return SourceExists
   End Function

この機能はFalseを返す場合、本サービスの起動時にコードを単純に停止するサービスです。この機能はかなりこまれのイベントソース名に関連する正しいイベントログファイルです。して再起動機の一;としなくてはならないだろうからサービスもあります。

私と同じです。私の場合このWindowsインストーラーは追加のイベントソースが同じ名前のとしてサービスを自動的にこのような原因です。を使用していま同じ名前のwindowsサービスのログ。に変更してみてくださいのでこのイベントログのソースは異なるその名のサービスです。

まだ投稿する方上にMSDNフォーラムにしたがいふく周辺のこの標準の設定MSIます。かった追加のコードのロック-ワイプしてイベントという思いもしになることを意味してい:

SortedList<string, string> eventSources = new SortedList<string, string>();
private void serviceProcessInstaller_BeforeInstall(object sender, InstallEventArgs e)
{
  RemoveServiceEventLogs();
}

private void RemoveServiceEventLogs()
{
  foreach (Installer installer in this.Installers)
    if (installer is ServiceInstaller)
    {
      ServiceInstaller serviceInstaller = installer as ServiceInstaller;
      if (EventLog.SourceExists(serviceInstaller.ServiceName))
      {
        eventSources.Add(serviceInstaller.ServiceName, EventLog.LogNameFromSourceName(serviceInstaller.ServiceName, Environment.MachineName));
        EventLog.DeleteEventSource(serviceInstaller.ServiceName);
      }
    }
}

private void serviceProcessInstaller_Committed(object sender, InstallEventArgs e)
{
  RemoveServiceEventLogs();
  foreach (KeyValuePair<string, string> eventSource in eventSources)
  {
    if (EventLog.SourceExists(eventSource.Key))
      EventLog.DeleteEventSource(eventSource.Key);

    EventLog.CreateEventSource(eventSource.Key, eventSource.Value);
  }
}

のコードを変更することができ、さらなるビットのみを削除しイベントソースがなかったの既存または作成(そのlognameい保存の必要がどこにインストーラが私のアプリケーションコードを実際に生のイベントソースしいパスワードを入力してあなた。がある場合でイベントがありする可能性がある。イベントソースです。っているか否かを確認するため、作成したりすることも可能ですが自動的に起動し、サービスです。

私も同様の奇妙な行動がって登録イベントソースと同じ名前のサービスいたします。

いるものではありませんのDisplayName設定と同じ名前のイベントソースです。

開始のサービス、またはWindowsログインし、"サービスを開始した"エントリのログには、ソースとして、DisplayName.こうして効果の登録 アプリケーション名 のプログです。

私のイベントのloggerクラスの後かたの登録 アプリケーション名 ソースとして別のイベントログがることは出来なかった新しいイベントログのエントリにいた追加のログです。

また、"説明のためのイベントID(0)ソース"のメッセージです。

としての周りだけどのような登録のメッセージのソースとなる名前の表示名での勤務を続けています。で試してみる価値は十分でありこださい。

の問題からinstallutilるデフォルトのレジスタのイベントソースサービスの名前に"アプリ"EventLog.まだ見しなければならないというニーズを停止してこのナメ.あ、私も全クリアできた素敵な場合に影響を及ぼす可能性がある行動にinstallutil:(

以下の helbの の提案ができない問題を修正した。殺人のデフォルトのイベントログインストーラの指示に彼の例では、予防から、インストーラを自動的に登録をWindowsのサービスのアプリケーションのイベントログです。

あまりにも多くの時間を失を解決しようとしてこの悔しいゴ.万!

FWIWることができなくなってし具体的な方法を以下に示す内私のデザイナー-発生ProjectInstallerクラスがVSに鯉のmod.私は廃車のデザイナー生成コードを手動で入力します。

追加空のレジストリキーをHKEY_LOCAL_MACHINE\制CurrentControlSet\サービス\eventlogリ\MY_CUSTOM_SOURCE_NAME_HEREう。

簡単でを何でもこなせます。デフォルトの動作(つまり、このプロジェクトインストーラを作成しますイベントログのソースの名前でサービスのベイジアンネットワークは簡単に変更のコンストラクタのプロジェクトでインストーラー、以下のことが明らかとなった。

[RunInstaller( true )]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
    public ProjectInstaller()
    {
        InitializeComponent();

        //Skip through all ServiceInstallers.
        foreach( ServiceInstaller ThisInstaller in Installers.OfType<ServiceInstaller>() )
        {
            //Find the first default EventLogInstaller.
            EventLogInstaller ThisLogInstaller = ThisInstaller.Installers.OfType<EventLogInstaller>().FirstOrDefault();
            if( ThisLogInstaller == null )
                continue;

            //Modify the used log from "Application" to the same name as the source name. This creates a source in the "Applications and Services log" which separates your service logs from the default application log.
            ThisLogInstaller.Log = ThisLogInstaller.Source;
        }
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top